zsolnai commited on
Commit
488462b
Β·
1 Parent(s): 1c33314

ui: make pretty :)

Browse files
Files changed (1) hide show
  1. app.py +69 -30
app.py CHANGED
@@ -8,55 +8,94 @@ import pandas as pd
8
  def get_data():
9
  file_path = "predictions.json"
10
  if not os.path.exists(file_path):
11
- return (
12
- pd.DataFrame({"Status": ["File not found yet. Run GitHub Action."]}),
13
- "N/A",
14
- )
15
 
16
  try:
17
  with open(file_path, "r") as f:
18
  raw_data = json.load(f)
19
 
20
- # 1. Extract the nested list
21
  predictions_list = raw_data.get("predictions", [])
22
  date = raw_data.get("prediction_date", "Unknown Date")
23
 
24
- # 2. Convert to DataFrame
25
  df = pd.DataFrame(predictions_list)
26
 
27
- # 3. Clean up the data (Optional but recommended)
28
  if not df.empty:
29
- # Sort by highest probability
30
  df = df.sort_values(by="probability", ascending=False)
31
- # Format probability to 2 decimal percentage (e.g., 0.953 -> 95.39%)
32
- df["probability"] = df["probability"].apply(lambda x: f"{x:.2%}")
33
- # Rename columns for a nicer UI
34
- df.columns = ["Repository", "Main Language", "Trend Probability"]
35
-
36
- return df, date
37
-
38
- except Exception as e:
39
- return pd.DataFrame({"Error": [str(e)]}), "Error"
40
 
 
 
 
 
41
 
42
- # Create the Gradio Interface
43
- with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
44
- gr.Markdown("# πŸš€ GitHub Trend Predictor")
45
 
46
- with gr.Row():
47
- date_display = gr.Textbox(label="Prediction Date", interactive=False)
48
 
49
- with gr.Row():
50
- # interactive=False removes the editing capability
51
- table = gr.Dataframe(interactive=False)
52
 
53
- refresh_btn = gr.Button("πŸ”„ Refresh Data")
54
 
55
- # Load data on startup
56
- demo.load(fn=get_data, outputs=[table, date_display])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- # Reload on button click
59
- refresh_btn.click(fn=get_data, outputs=[table, date_display])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  if __name__ == "__main__":
62
  demo.launch()
 
8
  def get_data():
9
  file_path = "predictions.json"
10
  if not os.path.exists(file_path):
11
+ return pd.DataFrame(), "N/A", None
 
 
 
12
 
13
  try:
14
  with open(file_path, "r") as f:
15
  raw_data = json.load(f)
16
 
 
17
  predictions_list = raw_data.get("predictions", [])
18
  date = raw_data.get("prediction_date", "Unknown Date")
19
 
 
20
  df = pd.DataFrame(predictions_list)
21
 
 
22
  if not df.empty:
 
23
  df = df.sort_values(by="probability", ascending=False)
 
 
 
 
 
 
 
 
 
24
 
25
+ # 1. Create a display version of the repo name (Clickable Link)
26
+ df["Repository"] = df["repo_name"].apply(
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
+ # 2. Prepare plot data (using raw numbers)
31
+ plot_df = df.copy()
 
32
 
33
+ # 3. Format percentage for the table
34
+ df["Trend Score"] = df["probability"].apply(lambda x: f"{x:.1%}")
35
 
36
+ # Final table selection
37
+ table_df = df[["Repository", "language", "Trend Score"]]
38
+ table_df.columns = ["Repository", "Language", "Trend Score"]
39
 
40
+ return table_df, f"πŸ“… Last Prediction Run: {date}", plot_df
41
 
42
+ except Exception as e:
43
+ return pd.DataFrame({"Error": [str(e)]}), "Error", None
44
+
45
+
46
+ # Custom CSS for a sleek, modern look
47
+ custom_css = """
48
+ footer {visibility: hidden}
49
+ .gradio-container {background-color: #0d1117 !important; color: white !important;}
50
+ table {border-collapse: collapse !important; border-radius: 8px !important; overflow: hidden !important;}
51
+ thead th {background-color: #161b22 !important; color: #8b949e !important;}
52
+ """
53
+
54
+ with gr.Blocks(
55
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"), css=custom_css
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
+ with gr.Row():
68
+ date_display = gr.Markdown(value="Loading data...", elem_id="date-box")
69
+
70
+ with gr.Tabs():
71
+ with gr.TabItem("πŸ“Š Probability Chart"):
72
+ # Horizontal Bar Plot
73
+ chart = gr.BarPlot(
74
+ x="repo_name",
75
+ y="probability",
76
+ title="Top Predicted Trends",
77
+ tooltip=["repo_name", "probability", "language"],
78
+ vertical=False,
79
+ y_label="Probability",
80
+ x_label="Repository",
81
+ container=True,
82
+ height=400,
83
+ color="language", # Colors bars by language
84
+ )
85
+
86
+ with gr.TabItem("πŸ“‹ Detailed List"):
87
+ # Table with HTML support for links
88
+ table = gr.Dataframe(
89
+ datatype=["html", "str", "str"], # Ensures links are clickable
90
+ interactive=False,
91
+ wrap=True,
92
+ )
93
+
94
+ refresh_btn = gr.Button("πŸ”„ Sync Latest Predictions", variant="primary")
95
+
96
+ # Wire up the data
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()