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

ui: fix grid plot

Browse files
Files changed (2) hide show
  1. app.py +32 -50
  2. requirements.txt +2 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
 
4
  import gradio as gr
5
  import pandas as pd
 
6
 
7
 
8
  def get_data():
@@ -16,85 +17,66 @@ def get_data():
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
- # 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
- )
 
3
 
4
  import gradio as gr
5
  import pandas as pd
6
+ import plotly.express as px
7
 
8
 
9
  def get_data():
 
17
 
18
  predictions_list = raw_data.get("predictions", [])
19
  date = raw_data.get("prediction_date", "Unknown Date")
 
20
  df = pd.DataFrame(predictions_list)
21
 
22
  if not df.empty:
23
+ df = df.sort_values(
24
+ by="probability", ascending=True
25
+ ) # Ascending for horizontal bar
26
+
27
+ # Create Plotly Chart
28
+ fig = px.bar(
29
+ df,
30
+ x="probability",
31
+ y="repo_name",
32
+ orientation="h",
33
+ color="language",
34
+ title="Trend Probability by Repository",
35
+ labels={
36
+ "probability": "Probability",
37
+ "repo_name": "Repository",
38
+ "language": "Language",
39
+ },
40
+ template="plotly_dark",
41
+ )
42
+ fig.update_layout(
43
+ paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)"
44
+ )
45
 
46
+ # Prepare Table
47
+ table_df = df.sort_values(by="probability", ascending=False).copy()
48
  table_df["repo_name"] = table_df["repo_name"].apply(
49
  lambda x: f'<a href="https://github.com/{x}" target="_blank" style="color: #58a6ff; text-decoration: none; font-weight: bold;">πŸ”— {x}</a>'
50
  )
 
 
51
  table_df["probability"] = table_df["probability"].apply(
52
  lambda x: f"{x:.1%}"
53
  )
 
 
54
  table_df = table_df[["repo_name", "language", "probability"]]
55
  table_df.columns = ["Repository", "Language", "Trend Probability"]
56
 
57
+ return table_df, f"πŸ“… Last Prediction Run: {date}", fig
58
 
59
  except Exception as e:
60
  return pd.DataFrame({"Error": [str(e)]}), "⚠️ Error loading data", None
61
 
62
 
 
 
 
 
 
 
 
63
  with gr.Blocks() as demo:
64
  gr.HTML(
65
+ '<div style="text-align: center; padding: 20px;"><h1 style="color: white;">πŸ“ˆ GitHub Trend Predictor</h1></div>'
 
 
 
 
 
66
  )
67
+ date_display = gr.Markdown(value="Checking for updates...")
 
 
68
 
69
  with gr.Tabs():
70
  with gr.Tab("πŸ“Š Visual Forecast"):
71
+ chart = gr.Plot() # Stable Plotly container
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  with gr.Tab("πŸ“‹ Detailed Rankings"):
74
+ table = gr.Dataframe(datatype=["html", "str", "str"], interactive=False)
 
 
75
 
76
  refresh_btn = gr.Button("πŸ”„ Sync Latest Predictions", variant="primary")
 
 
77
  demo.load(fn=get_data, outputs=[table, date_display, chart])
 
78
  refresh_btn.click(fn=get_data, outputs=[table, date_display, chart])
79
 
80
  if __name__ == "__main__":
81
+ # We remove CSS/Theme from here to ensure the core app starts even if Gradio 6.x config is strict
82
+ demo.launch()
 
 
 
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
- gradio
2
  pandas
 
 
1
+ gradio>=6.0.0
2
  pandas
3
+ plotly