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

ui: fix vertical issue

Browse files
Files changed (1) hide show
  1. app.py +60 -61
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(), "N/A", None
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
- # 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()
 
 
 
 
 
 
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
+ )