Spaces:
Sleeping
Sleeping
zsolnai commited on
Commit Β·
ab7c77d
1
Parent(s): c50a131
ui: fix the error
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ def get_data():
|
|
| 20 |
df = pd.DataFrame(predictions_list)
|
| 21 |
|
| 22 |
if not df.empty:
|
| 23 |
-
# Sort for Chart (
|
| 24 |
chart_df = df.sort_values(by="probability", ascending=True)
|
| 25 |
|
| 26 |
fig = px.bar(
|
|
@@ -36,15 +36,15 @@ def get_data():
|
|
| 36 |
"language": "Language",
|
| 37 |
},
|
| 38 |
template="plotly_dark",
|
| 39 |
-
color_discrete_sequence=px.colors.qualitative.Safe,
|
| 40 |
)
|
| 41 |
fig.update_layout(
|
| 42 |
paper_bgcolor="rgba(0,0,0,0)",
|
| 43 |
plot_bgcolor="rgba(0,0,0,0)",
|
| 44 |
font_color="#8b949e",
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
-
# Prepare Table (
|
| 48 |
table_df = df.sort_values(by="probability", ascending=False).copy()
|
| 49 |
table_df["repo_name"] = table_df["repo_name"].apply(
|
| 50 |
lambda x: f'<a href="https://github.com/{x}" target="_blank" style="color: #58a6ff; text-decoration: none; font-weight: bold;">π {x}</a>'
|
|
@@ -55,35 +55,41 @@ def get_data():
|
|
| 55 |
table_df = table_df[["repo_name", "language", "probability"]]
|
| 56 |
table_df.columns = ["Repository", "Language", "Trend Probability"]
|
| 57 |
|
| 58 |
-
return table_df, f"π
Last Prediction Run:
|
| 59 |
|
| 60 |
except Exception as e:
|
| 61 |
-
return pd.DataFrame({"Error": [str(e)]}), "β οΈ Error loading data", None
|
| 62 |
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
gr.HTML(
|
| 66 |
-
'<div style="text-align: center; padding: 10px;"><h1 style="color: #f0f6fc;">π GitHub Trend Predictor</h1></div>'
|
| 67 |
)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
# We wrap the tabs in a variable to attach the listener
|
| 73 |
with gr.Tabs() as tabs:
|
| 74 |
-
with gr.Tab("π Visual Forecast"
|
| 75 |
chart = gr.Plot()
|
| 76 |
|
| 77 |
-
with gr.Tab("π Detailed Rankings"
|
| 78 |
table = gr.Dataframe(datatype=["html", "str", "str"], interactive=False)
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
#
|
| 83 |
demo.load(fn=get_data, outputs=[table, date_display, chart])
|
| 84 |
-
|
| 85 |
-
# 2. Sync whenever a user clicks/switches between tabs
|
| 86 |
tabs.select(fn=get_data, outputs=[table, date_display, chart])
|
|
|
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
-
|
|
|
|
|
|
| 20 |
df = pd.DataFrame(predictions_list)
|
| 21 |
|
| 22 |
if not df.empty:
|
| 23 |
+
# Sort for Chart (Ascending for horizontal Plotly layout)
|
| 24 |
chart_df = df.sort_values(by="probability", ascending=True)
|
| 25 |
|
| 26 |
fig = px.bar(
|
|
|
|
| 36 |
"language": "Language",
|
| 37 |
},
|
| 38 |
template="plotly_dark",
|
|
|
|
| 39 |
)
|
| 40 |
fig.update_layout(
|
| 41 |
paper_bgcolor="rgba(0,0,0,0)",
|
| 42 |
plot_bgcolor="rgba(0,0,0,0)",
|
| 43 |
font_color="#8b949e",
|
| 44 |
+
margin=dict(l=20, r=20, t=40, b=20),
|
| 45 |
)
|
| 46 |
|
| 47 |
+
# Prepare Table (Descending for the list view)
|
| 48 |
table_df = df.sort_values(by="probability", ascending=False).copy()
|
| 49 |
table_df["repo_name"] = table_df["repo_name"].apply(
|
| 50 |
lambda x: f'<a href="https://github.com/{x}" target="_blank" style="color: #58a6ff; text-decoration: none; font-weight: bold;">π {x}</a>'
|
|
|
|
| 55 |
table_df = table_df[["repo_name", "language", "probability"]]
|
| 56 |
table_df.columns = ["Repository", "Language", "Trend Probability"]
|
| 57 |
|
| 58 |
+
return table_df, f"### π
Last Prediction Run: {date}", fig
|
| 59 |
|
| 60 |
except Exception as e:
|
| 61 |
+
return pd.DataFrame({"Error": [str(e)]}), "### β οΈ Error loading data", None
|
| 62 |
|
| 63 |
|
| 64 |
+
# CSS to center the markdown text since 'style' is no longer allowed in components
|
| 65 |
+
custom_css = """
|
| 66 |
+
#date-container { text-align: center; margin-bottom: 20px; }
|
| 67 |
+
.gradio-container { background-color: #0d1117 !important; }
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
with gr.Blocks() as demo:
|
| 71 |
gr.HTML(
|
| 72 |
+
'<div style="text-align: center; padding: 10px;"><h1 style="color: #f0f6fc; margin-bottom: 0;">π GitHub Trend Predictor</h1></div>'
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# Use a container to handle alignment via CSS
|
| 76 |
+
with gr.Column(elem_id="date-container"):
|
| 77 |
+
date_display = gr.Markdown(value="Syncing...")
|
| 78 |
|
|
|
|
| 79 |
with gr.Tabs() as tabs:
|
| 80 |
+
with gr.Tab("π Visual Forecast"):
|
| 81 |
chart = gr.Plot()
|
| 82 |
|
| 83 |
+
with gr.Tab("π Detailed Rankings"):
|
| 84 |
table = gr.Dataframe(datatype=["html", "str", "str"], interactive=False)
|
| 85 |
|
| 86 |
+
refresh_btn = gr.Button("π Sync Latest Predictions", variant="primary")
|
| 87 |
|
| 88 |
+
# Listeners
|
| 89 |
demo.load(fn=get_data, outputs=[table, date_display, chart])
|
|
|
|
|
|
|
| 90 |
tabs.select(fn=get_data, outputs=[table, date_display, chart])
|
| 91 |
+
refresh_btn.click(fn=get_data, outputs=[table, date_display, chart])
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
+
# Parameters moved to launch() for Gradio 6.0 compatibility
|
| 95 |
+
demo.launch(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css)
|