dibend commited on
Commit
46a4330
·
verified ·
1 Parent(s): 264317d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -3
app.py CHANGED
@@ -24,7 +24,7 @@ def plot_csv():
24
  df = df.drop(columns=['Unnamed: 2'])
25
 
26
  # Rename columns for easier use
27
- df.columns = ['Date', 'Median Sales Price - Entire Garden State MLS']
28
 
29
  # Create a Plotly figure
30
  fig = go.Figure()
@@ -34,7 +34,7 @@ def plot_csv():
34
 
35
  # Update the plot layout for a professional look
36
  fig.update_layout(
37
- title="Median Sales Price - Entire Garden State MLS",
38
  xaxis_title="Date",
39
  yaxis_title="Median Sales Price ($)",
40
  showlegend=True
@@ -44,7 +44,28 @@ def plot_csv():
44
 
45
  except Exception as e:
46
  # If there's an error fetching or plotting the data, return the error message
47
- return str(e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
 
50
  # Set up the Gradio interface
@@ -52,6 +73,14 @@ with gr.Blocks() as demo:
52
  gr.Markdown("## Median Sales Price Plotter")
53
  plot_output = gr.Plot()
54
  run_button = gr.Button("Plot Data")
 
 
 
 
 
 
 
 
55
 
56
  # Link the button to the plotting function
57
  run_button.click(plot_csv, inputs=None, outputs=plot_output)
 
24
  df = df.drop(columns=['Unnamed: 2'])
25
 
26
  # Rename columns for easier use
27
+ df.columns = ['Date', 'Median Sales Price']
28
 
29
  # Create a Plotly figure
30
  fig = go.Figure()
 
34
 
35
  # Update the plot layout for a professional look
36
  fig.update_layout(
37
+ title="Median Sales Price - Entire MLS",
38
  xaxis_title="Date",
39
  yaxis_title="Median Sales Price ($)",
40
  showlegend=True
 
44
 
45
  except Exception as e:
46
  # If there's an error fetching or plotting the data, return the error message
47
+ # This is useful for debugging connection issues with the URL
48
+ error_message = f"An error occurred: {e}. Please check the console for details."
49
+ print(error_message) # Print full error to console
50
+ # Create an empty plot with an error annotation
51
+ fig = go.Figure()
52
+ fig.update_layout(
53
+ title="Error Loading Data",
54
+ xaxis={"visible": False},
55
+ yaxis={"visible": False},
56
+ annotations=[
57
+ {
58
+ "text": "Could not load data from the source URL.<br>Please check the connection or URL.",
59
+ "xref": "paper",
60
+ "yref": "paper",
61
+ "showarrow": False,
62
+ "font": {
63
+ "size": 16
64
+ }
65
+ }
66
+ ]
67
+ )
68
+ return fig
69
 
70
 
71
  # Set up the Gradio interface
 
73
  gr.Markdown("## Median Sales Price Plotter")
74
  plot_output = gr.Plot()
75
  run_button = gr.Button("Plot Data")
76
+
77
+ # Add the data source disclosure at the bottom
78
+ gr.Markdown(
79
+ """
80
+ ---
81
+ *Data provided by the Garden State Multiple Listing Service. For internal use only.*
82
+ """
83
+ )
84
 
85
  # Link the button to the plotting function
86
  run_button.click(plot_csv, inputs=None, outputs=plot_output)