Spaces:
Sleeping
Sleeping
zsolnai commited on
Commit Β·
b9f524c
1
Parent(s): 488462b
ui: fix vertical issue
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import pandas as pd
|
|
| 8 |
def get_data():
|
| 9 |
file_path = "predictions.json"
|
| 10 |
if not os.path.exists(file_path):
|
| 11 |
-
return pd.DataFrame(), "
|
| 12 |
|
| 13 |
try:
|
| 14 |
with open(file_path, "r") as f:
|
|
@@ -20,82 +20,81 @@ def get_data():
|
|
| 20 |
df = pd.DataFrame(predictions_list)
|
| 21 |
|
| 22 |
if not df.empty:
|
|
|
|
| 23 |
df = df.sort_values(by="probability", ascending=False)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
| 27 |
lambda x: f'<a href="https://github.com/{x}" target="_blank" style="color: #58a6ff; text-decoration: none; font-weight: bold;">π {x}</a>'
|
| 28 |
)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
df["Trend Score"] = df["probability"].apply(lambda x: f"{x:.1%}")
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
table_df =
|
| 38 |
-
table_df.columns = ["Repository", "Language", "Trend
|
| 39 |
|
| 40 |
-
return table_df, f"π
Last Prediction Run: {date}",
|
| 41 |
|
| 42 |
except Exception as e:
|
| 43 |
-
return pd.DataFrame({"Error": [str(e)]}), "Error", None
|
| 44 |
|
| 45 |
|
| 46 |
-
#
|
| 47 |
custom_css = """
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
thead th {background-color: #161b22 !important; color: #8b949e !important;}
|
| 52 |
"""
|
| 53 |
|
| 54 |
-
with gr.Blocks(
|
| 55 |
-
|
| 56 |
-
) as demo:
|
| 57 |
-
with gr.Column(elem_id="container"):
|
| 58 |
-
gr.HTML(
|
| 59 |
-
"""
|
| 60 |
-
<div style="text-align: center; padding: 20px;">
|
| 61 |
-
<h1 style="font-size: 2.5em; margin-bottom: 0px;">π GitHub Trend Predictor</h1>
|
| 62 |
-
<p style="color: #8b949e;">AI-powered forecast of the next big repositories</p>
|
| 63 |
-
</div>
|
| 64 |
"""
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
demo.load(fn=get_data, outputs=[table, date_display, chart])
|
|
|
|
| 98 |
refresh_btn.click(fn=get_data, outputs=[table, date_display, chart])
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
| 101 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def get_data():
|
| 9 |
file_path = "predictions.json"
|
| 10 |
if not os.path.exists(file_path):
|
| 11 |
+
return pd.DataFrame(), "π
Status: Waiting for data sync...", None
|
| 12 |
|
| 13 |
try:
|
| 14 |
with open(file_path, "r") as f:
|
|
|
|
| 20 |
df = pd.DataFrame(predictions_list)
|
| 21 |
|
| 22 |
if not df.empty:
|
| 23 |
+
# Sort by highest probability for both chart and table
|
| 24 |
df = df.sort_values(by="probability", ascending=False)
|
| 25 |
|
| 26 |
+
# Create a copy for the table with HTML links
|
| 27 |
+
table_df = df.copy()
|
| 28 |
+
table_df["repo_name"] = table_df["repo_name"].apply(
|
| 29 |
lambda x: f'<a href="https://github.com/{x}" target="_blank" style="color: #58a6ff; text-decoration: none; font-weight: bold;">π {x}</a>'
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Format percentage for the table view
|
| 33 |
+
table_df["probability"] = table_df["probability"].apply(
|
| 34 |
+
lambda x: f"{x:.1%}"
|
| 35 |
+
)
|
|
|
|
| 36 |
|
| 37 |
+
# Select and rename columns for display
|
| 38 |
+
table_df = table_df[["repo_name", "language", "probability"]]
|
| 39 |
+
table_df.columns = ["Repository", "Language", "Trend Probability"]
|
| 40 |
|
| 41 |
+
return table_df, f"π
Last Prediction Run: {date}", df
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
+
return pd.DataFrame({"Error": [str(e)]}), "β οΈ Error loading data", None
|
| 45 |
|
| 46 |
|
| 47 |
+
# Modern GitHub-like CSS
|
| 48 |
custom_css = """
|
| 49 |
+
.gradio-container {background-color: #0d1117 !important;}
|
| 50 |
+
label {color: #8b949e !important;}
|
| 51 |
+
footer {display: none !important;}
|
|
|
|
| 52 |
"""
|
| 53 |
|
| 54 |
+
with gr.Blocks() as demo:
|
| 55 |
+
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
"""
|
| 57 |
+
<div style="text-align: center; padding: 20px; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif;">
|
| 58 |
+
<h1 style="font-size: 2.2em; color: #f0f6fc; margin-bottom: 8px;">π GitHub Trend Predictor</h1>
|
| 59 |
+
<p style="color: #8b949e; font-size: 1.1em;">Daily AI forecast of emerging repositories</p>
|
| 60 |
+
</div>
|
| 61 |
+
"""
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
with gr.Row():
|
| 65 |
+
date_display = gr.Markdown(value="Checking for updates...", elem_id="date-box")
|
| 66 |
+
|
| 67 |
+
with gr.Tabs():
|
| 68 |
+
with gr.Tab("π Visual Forecast"):
|
| 69 |
+
chart = gr.BarPlot(
|
| 70 |
+
x="repo_name",
|
| 71 |
+
y="probability",
|
| 72 |
+
title="Trend Probability by Repository",
|
| 73 |
+
tooltip=["repo_name", "probability", "language"],
|
| 74 |
+
direction="horizontal",
|
| 75 |
+
y_label="Probability",
|
| 76 |
+
x_label="Repository",
|
| 77 |
+
color="language",
|
| 78 |
+
height=450,
|
| 79 |
+
container=True,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
with gr.Tab("π Detailed Rankings"):
|
| 83 |
+
table = gr.Dataframe(
|
| 84 |
+
datatype=["html", "str", "str"], interactive=False, wrap=True
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
refresh_btn = gr.Button("π Sync Latest Predictions", variant="primary")
|
| 88 |
+
|
| 89 |
+
# Load data on page entry
|
| 90 |
demo.load(fn=get_data, outputs=[table, date_display, chart])
|
| 91 |
+
# Manual refresh
|
| 92 |
refresh_btn.click(fn=get_data, outputs=[table, date_display, chart])
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
+
demo.launch(
|
| 96 |
+
theme=gr.themes.Soft(
|
| 97 |
+
primary_hue="blue", secondary_hue="slate", font=["Inter", "sans-serif"]
|
| 98 |
+
),
|
| 99 |
+
css=custom_css,
|
| 100 |
+
)
|