zsolnai commited on
Commit
872eb3c
Β·
1 Parent(s): 91d11d8

feat(gradio): switch to gradio

Browse files
Files changed (3) hide show
  1. README.md +1 -3
  2. app.py +31 -25
  3. requirements.txt +1 -1
README.md CHANGED
@@ -4,9 +4,7 @@ emoji: πŸ’»
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.2.0
8
  app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 4.19.2
8
  app_file: app.py
9
  pinned: false
10
  ---
 
 
app.py CHANGED
@@ -1,30 +1,36 @@
1
  import json
2
  import os
3
 
 
4
  import pandas as pd
5
- import streamlit as st
6
-
7
- st.set_page_config(page_title="GitHub Trend Predictor", page_icon="πŸ“ˆ")
8
- st.title("πŸ“ˆ GitHub Trend Predictions")
9
-
10
- # Path to the file pushed by your GitHub Action
11
- file_path = "predictions.json"
12
-
13
- if os.path.exists(file_path):
14
- with open(file_path, "r") as f:
15
- data = json.load(f)
16
-
17
- st.success(f"Last updated: {os.path.getmtime(file_path)}")
18
-
19
- # Display as a searchable/sortable table if it's a list
20
- if isinstance(data, list):
21
- df = pd.DataFrame(data)
22
- st.dataframe(df, use_container_width=True)
23
- else:
24
- # Fallback for nested JSON
25
- st.json(data)
26
- else:
27
- st.info("Waiting for the first data sync from GitHub...")
28
- st.image(
29
- "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/wait.png"
30
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import json
2
  import os
3
 
4
+ import gradio as gr
5
  import pandas as pd
6
+
7
+
8
+ def get_data():
9
+ file_path = "predictions.json"
10
+ if os.path.exists(file_path):
11
+ try:
12
+ with open(file_path, "r") as f:
13
+ data = json.load(f)
14
+ # Assuming predictions.json is a list of dicts
15
+ return pd.DataFrame(data)
16
+ except Exception as e:
17
+ return pd.DataFrame({"Error": [f"Failed to parse JSON: {e}"]})
18
+ return pd.DataFrame(
19
+ {"Status": ["predictions.json not found. Run your GitHub Action to push data!"]}
 
 
 
 
 
 
 
 
 
 
 
20
  )
21
+
22
+
23
+ # Create the Gradio Interface
24
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
25
+ gr.Markdown("# πŸš€ GitHub Trend Predictor")
26
+ gr.Markdown("Visualizing trending repositories pushed from GitHub Actions.")
27
+
28
+ with gr.Row():
29
+ # This will automatically load the data when the page opens
30
+ table = gr.Dataframe(value=get_data, interactive=False)
31
+
32
+ refresh_btn = gr.Button("πŸ”„ Refresh Table")
33
+ refresh_btn.click(fn=get_data, outputs=table)
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- streamlit
2
  pandas
 
1
+ gradio
2
  pandas