Spaces:
Build error
Build error
Upload 7 files
Browse files- app.py +6 -7
- src/trend_utils.py +20 -22
app.py
CHANGED
|
@@ -61,12 +61,7 @@ def select_version_df(name):
|
|
| 61 |
"""
|
| 62 |
MAIN APPLICATION
|
| 63 |
"""
|
| 64 |
-
hf_app = gr.Blocks(
|
| 65 |
-
#trend-plot-1, .gr-plot {
|
| 66 |
-
width: 100% !important;
|
| 67 |
-
max-width: 100vw !important;
|
| 68 |
-
}
|
| 69 |
-
""")
|
| 70 |
with hf_app:
|
| 71 |
gr.HTML(TITLE)
|
| 72 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
|
@@ -371,7 +366,10 @@ with hf_app:
|
|
| 371 |
)
|
| 372 |
|
| 373 |
with gr.Row():
|
| 374 |
-
trend_plot = gr.Plot(get_final_trend_plot("Text",
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
trend_select.change(
|
| 377 |
get_final_trend_plot,
|
|
@@ -440,6 +438,7 @@ with hf_app:
|
|
| 440 |
dummy_prev_table,
|
| 441 |
queue=True
|
| 442 |
)
|
|
|
|
| 443 |
hf_app.load()
|
| 444 |
hf_app.queue()
|
| 445 |
|
|
|
|
| 61 |
"""
|
| 62 |
MAIN APPLICATION
|
| 63 |
"""
|
| 64 |
+
hf_app = gr.Blocks()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
with hf_app:
|
| 66 |
gr.HTML(TITLE)
|
| 67 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
|
|
|
| 366 |
)
|
| 367 |
|
| 368 |
with gr.Row():
|
| 369 |
+
trend_plot = gr.Plot(get_final_trend_plot(benchmark="Text",
|
| 370 |
+
mobile_view=False,
|
| 371 |
+
custom_width=1200),
|
| 372 |
+
show_label=False)
|
| 373 |
|
| 374 |
trend_select.change(
|
| 375 |
get_final_trend_plot,
|
|
|
|
| 438 |
dummy_prev_table,
|
| 439 |
queue=True
|
| 440 |
)
|
| 441 |
+
|
| 442 |
hf_app.load()
|
| 443 |
hf_app.queue()
|
| 444 |
|
src/trend_utils.py
CHANGED
|
@@ -201,7 +201,7 @@ def get_plot(df: pd.DataFrame, start_date: str = '2023-06-01', end_date: str = '
|
|
| 201 |
open_dip = plot_kwargs['open_dip']
|
| 202 |
comm_dip = plot_kwargs['comm_dip']
|
| 203 |
height = plot_kwargs['height']
|
| 204 |
-
|
| 205 |
|
| 206 |
mobile_view = True if plot_kwargs['mobile_view'] else False
|
| 207 |
|
|
@@ -318,7 +318,6 @@ def get_plot(df: pd.DataFrame, start_date: str = '2023-06-01', end_date: str = '
|
|
| 318 |
benchmark_tick_texts = []
|
| 319 |
for i in range(len(benchmark_tickvals)):
|
| 320 |
benchmark_tick_texts.append(f"<br><br><b>{benchmark_ticks[benchmark_tickvals[i]]}</b>")
|
| 321 |
-
|
| 322 |
fig.update_xaxes(
|
| 323 |
tickvals=filtered_custom_tickvals + benchmark_tickvals, # Use filtered_custom_tickvals
|
| 324 |
ticktext=[f"{date.strftime('%b')}<br>{date.strftime('%y')}" for date in filtered_custom_tickvals] +
|
|
@@ -371,29 +370,29 @@ def get_plot(df: pd.DataFrame, start_date: str = '2023-06-01', end_date: str = '
|
|
| 371 |
)
|
| 372 |
)
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
if mobile_view:
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
if custom_width:
|
| 389 |
-
# Use a custom width for loading the graph for the first time
|
| 390 |
-
# Gets squished on initial loading as container width defaults to None while rendering for the first time
|
| 391 |
-
fig.update_layout(width=custom_width)
|
| 392 |
|
| 393 |
return fig
|
| 394 |
|
| 395 |
|
| 396 |
-
def get_final_trend_plot(benchmark: str = "Text", mobile_view: bool = False, custom_width=None) -> go.Figure:
|
| 397 |
"""Fetch and generate the final trend plot for all models.
|
| 398 |
|
| 399 |
Args:
|
|
@@ -422,8 +421,7 @@ def get_final_trend_plot(benchmark: str = "Text", mobile_view: bool = False, cus
|
|
| 422 |
else:
|
| 423 |
height = 1000
|
| 424 |
|
| 425 |
-
|
| 426 |
-
plot_kwargs = {'height': height, 'custom_width': custom_width, 'open_dip': 0, 'comm_dip': 0,
|
| 427 |
'mobile_view': mobile_view}
|
| 428 |
|
| 429 |
benchmark_ticks = {}
|
|
|
|
| 201 |
open_dip = plot_kwargs['open_dip']
|
| 202 |
comm_dip = plot_kwargs['comm_dip']
|
| 203 |
height = plot_kwargs['height']
|
| 204 |
+
width = plot_kwargs['width']
|
| 205 |
|
| 206 |
mobile_view = True if plot_kwargs['mobile_view'] else False
|
| 207 |
|
|
|
|
| 318 |
benchmark_tick_texts = []
|
| 319 |
for i in range(len(benchmark_tickvals)):
|
| 320 |
benchmark_tick_texts.append(f"<br><br><b>{benchmark_ticks[benchmark_tickvals[i]]}</b>")
|
|
|
|
| 321 |
fig.update_xaxes(
|
| 322 |
tickvals=filtered_custom_tickvals + benchmark_tickvals, # Use filtered_custom_tickvals
|
| 323 |
ticktext=[f"{date.strftime('%b')}<br>{date.strftime('%y')}" for date in filtered_custom_tickvals] +
|
|
|
|
| 370 |
)
|
| 371 |
)
|
| 372 |
|
| 373 |
+
if width:
|
| 374 |
+
print("Custom Seting the Width :")
|
| 375 |
+
fig.update_layout(width=width)
|
| 376 |
+
|
| 377 |
if mobile_view:
|
| 378 |
+
# Fix plot dimensions for a cleaner view
|
| 379 |
+
fig.update_layout(
|
| 380 |
+
height=400, # shorter plot for mobile
|
| 381 |
+
margin=dict(l=10, r=10, t=30, b=40),
|
| 382 |
+
font=dict(size=5),
|
| 383 |
+
legend=dict(font=dict(size=7),
|
| 384 |
+
bgcolor='rgba(255,255,255,0.7)', # semi-transparent white for mobile
|
| 385 |
+
bordercolor='rgba(0,0,0,0.05)'),
|
| 386 |
+
xaxis=dict(tickfont=dict(size=7)),
|
| 387 |
+
yaxis=dict(tickfont=dict(size=7)),
|
| 388 |
+
title=dict(font=dict(size=13)),
|
| 389 |
+
|
| 390 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
return fig
|
| 393 |
|
| 394 |
|
| 395 |
+
def get_final_trend_plot(benchmark: str = "Text", mobile_view: bool = False, custom_width: int = None) -> go.Figure:
|
| 396 |
"""Fetch and generate the final trend plot for all models.
|
| 397 |
|
| 398 |
Args:
|
|
|
|
| 421 |
else:
|
| 422 |
height = 1000
|
| 423 |
|
| 424 |
+
plot_kwargs = {'height': height, 'width': custom_width, 'open_dip': 0, 'comm_dip': 0,
|
|
|
|
| 425 |
'mobile_view': mobile_view}
|
| 426 |
|
| 427 |
benchmark_ticks = {}
|