| import gradio as gr |
| import pandas as pd |
| import plotly.graph_objects as go |
|
|
| |
| CSV_URL = "https://gardenstatemls.stats.showingtime.com/infoserv/s-v1/kpou-Asg" |
|
|
| def plot_csv(): |
| """ |
| Reads data from the specified URL, processes it, and creates a plot. |
| |
| This function skips the first 9 rows of the CSV, which contain metadata, |
| and removes any empty columns before plotting the data. |
| |
| Returns: |
| A Plotly figure object showing the median sales price over time. |
| """ |
| try: |
| |
| df = pd.read_csv(CSV_URL, skiprows=9) |
|
|
| |
| if 'Unnamed: 2' in df.columns: |
| df = df.drop(columns=['Unnamed: 2']) |
|
|
| |
| df.columns = ['Date', 'Median Sales Price'] |
|
|
| |
| fig = go.Figure() |
|
|
| |
| fig.add_trace(go.Scatter(x=df['Date'], y=df['Median Sales Price'], mode='lines', name='Median Sales Price')) |
|
|
| |
| fig.update_layout( |
| title="Median Sales Price - Entire MLS", |
| xaxis_title="Date", |
| yaxis_title="Median Sales Price ($)", |
| showlegend=True |
| ) |
|
|
| return fig |
|
|
| except Exception as e: |
| |
| return str(e) |
|
|
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("## Median Sales Price Plotter") |
| plot_output = gr.Plot() |
| run_button = gr.Button("Plot Data") |
|
|
| |
| run_button.click(plot_csv, inputs=None, outputs=plot_output) |
|
|
| |
| demo.launch(debug=True) |