Spaces:
Sleeping
Sleeping
zsolnai commited on
Commit Β·
872eb3c
1
Parent(s): 91d11d8
feat(gradio): switch to gradio
Browse files- README.md +1 -3
- app.py +31 -25
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,9 +4,7 @@ emoji: π»
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 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 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
file_path
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 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 |
-
|
| 2 |
pandas
|
|
|
|
| 1 |
+
gradio
|
| 2 |
pandas
|