Download app.py from 159333G4/SSS: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/159333G4/SSS/resolve/main/app.py
- Command line
-
hf download hf://spaces/159333G4/SSS/app.py
-
curl -L -o app.py https://huggingface.co/spaces/159333G4/SSS/resolve/main/app.py
1.51 kB
| try: | |
| import plotly.express as px | |
| except ImportError: | |
| import os | |
| os.system("pip install plotly>=5.20.0") | |
| import plotly.express as px | |
| import pandas as pd | |
| #import plotly.express as px | |
| import gradio as gr | |
| # 读取模拟数据 | |
| df = pd.read_csv("trend_prediction.csv", parse_dates=["date"]) | |
| # 主函数:根据用户选择过滤数据并绘图 | |
| def plot_disease_trend(disease, start_date, end_date): | |
| filtered = df[ | |
| (df["disease"] == disease) & | |
| (df["date"] >= pd.to_datetime(start_date)) & | |
| (df["date"] <= pd.to_datetime(end_date)) | |
| ] | |
| if filtered.empty: | |
| return "⚠️ 没有数据可显示,请重新选择时间段。" | |
| fig = px.line( | |
| filtered, | |
| x="date", | |
| y=["trend_score", "case_reported", "predicted_case"], | |
| labels={"value": "数量", "variable": "数据类型"}, | |
| title=f"{disease.title()} 趋势对比图" | |
| ) | |
| fig.update_layout(xaxis_title="日期", yaxis_title="数量") | |
| return fig | |
| # Gradio UI 设置 | |
| demo = gr.Interface( | |
| fn=plot_disease_trend, | |
| inputs=[ | |
| gr.Dropdown(choices=df["disease"].unique().tolist(), label="选择疾病"), | |
| gr.DateTime(label="开始日期"), | |
| gr.DateTime(label="结束日期") | |
| ], | |
| outputs=gr.Plot(label="趋势图"), | |
| title="Livestock Health Trend Viewer", | |
| description="选择一个疾病和时间段,查看 Google Trends 与病例趋势的对比图。" | |
| ) | |
| # 启动网站 | |
| if __name__ == "__main__": | |
| demo.launch() | |