dibend commited on
Commit
7d09608
·
verified ·
1 Parent(s): 874341a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -27
app.py CHANGED
@@ -1,36 +1,22 @@
1
- import gradio as gr
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
 
5
  CSV_URL = "https://gardenstatemls.stats.showingtime.com/infoserv/s-v1/kpou-Asg"
6
 
7
- # Function to fetch and plot CSV data
8
- def plot_csv():
9
- # Read CSV directly from URL
10
- df = pd.read_csv(CSV_URL)
11
 
12
- # Create a simple plot - adjust as needed based on CSV columns
13
- plt.figure(figsize=(10, 6))
14
- df.plot(x=df.columns[0], y=df.columns[1:], marker='o')
15
- plt.title("CSV Data Plot")
16
- plt.xlabel(df.columns[0])
17
- plt.ylabel("Values")
18
- plt.grid(True)
19
- plt.tight_layout()
20
 
21
- # Save the plot to a file
22
- plt.savefig("plot.png")
23
- plt.close()
 
 
24
 
25
- return "plot.png"
 
26
 
27
- # Gradio Interface
28
- demo = gr.Interface(
29
- fn=plot_csv,
30
- inputs=[],
31
- outputs=gr.Image(type="filepath"),
32
- title="CSV Plotter",
33
- description="This Space downloads the CSV from GSMLS"
34
- )
35
 
36
  demo.launch(debug=True)
 
1
+ import gradio as gr import pandas as pd import plotly.express as px import plotly.graph_objects as go
 
 
2
 
3
  CSV_URL = "https://gardenstatemls.stats.showingtime.com/infoserv/s-v1/kpou-Asg"
4
 
5
+ def plot_csv(area): df = pd.read_csv(CSV_URL) fig = go.Figure()
 
 
 
6
 
7
+ # Add full data traces
8
+ for col in df.columns[1:]:
9
+ fig.add_trace(go.Scatter(x=df[df.columns[0]], y=df[col], mode='lines', name=col))
 
 
 
 
 
10
 
11
+ # Add filtered trace if area is specified
12
+ if area and 'Area' in df.columns:
13
+ filtered_df = df[df['Area'].str.contains(area, case=False, na=False)]
14
+ for col in filtered_df.columns[1:]:
15
+ fig.add_trace(go.Scatter(x=filtered_df[filtered_df.columns[0]], y=filtered_df[col], mode='lines+markers', name=f"Filtered: {col} ({area})"))
16
 
17
+ fig.update_layout(title="Full CSV Data Plot with Area Filter Overlay")
18
+ return fig
19
 
20
+ with gr.Blocks() as demo: gr.Markdown("## Interactive CSV Plotter (Full Plot + Area Filter Overlay)") area_input = gr.Textbox(label="Filter Area", placeholder="Enter area name to highlight") plot_output = gr.Plot() run_button = gr.Button("Plot") run_button.click(plot_csv, inputs=area_input, outputs=plot_output)
 
 
 
 
 
 
 
21
 
22
  demo.launch(debug=True)