Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
import plotly.
|
4 |
|
5 |
def plot_real_estate(state):
|
6 |
# Read the CSV file
|
7 |
df = pd.read_csv('https://files.zillowstatic.com/research/public_csvs/zhvi/Zip_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv')
|
8 |
|
9 |
# Filter for the given state
|
10 |
-
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
# Loop through each ZIP code and add a plot line
|
19 |
-
for zip_code in zip_codes:
|
20 |
-
df_zip = df_state[df_state['RegionName'] == zip_code]
|
21 |
|
22 |
# Select the columns with dates and transpose the data
|
23 |
df_zip = df_zip.loc[:, '2000-01-31':].T.reset_index()
|
@@ -26,17 +23,18 @@ def plot_real_estate(state):
|
|
26 |
# Convert 'Date' to datetime
|
27 |
df_zip['Date'] = pd.to_datetime(df_zip['Date'])
|
28 |
|
29 |
-
#
|
30 |
-
fig.
|
31 |
|
32 |
# Update plot layout
|
33 |
fig.update_layout(title=f'Housing Prices in {state}',
|
34 |
xaxis_title='Date',
|
35 |
yaxis_title='Price')
|
|
|
36 |
return fig
|
37 |
|
38 |
iface = gr.Interface(fn=plot_real_estate,
|
39 |
-
inputs=[gr.components.Textbox(label="State (e.g., NJ for New Jersey)")],
|
40 |
outputs=gr.Plot())
|
41 |
|
42 |
iface.launch(share=False, debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import plotly.graph_objects as go
|
4 |
|
5 |
def plot_real_estate(state):
|
6 |
# Read the CSV file
|
7 |
df = pd.read_csv('https://files.zillowstatic.com/research/public_csvs/zhvi/Zip_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv')
|
8 |
|
9 |
# Filter for the given state
|
10 |
+
df = df[df['State'] == state.upper()]
|
11 |
|
12 |
+
# Initialize a Plotly graph object
|
13 |
+
fig = go.Figure()
|
14 |
|
15 |
+
# Loop through each ZIP code in the state
|
16 |
+
for zip_code in df['RegionName'].unique():
|
17 |
+
df_zip = df[df['RegionName'] == zip_code]
|
|
|
|
|
|
|
18 |
|
19 |
# Select the columns with dates and transpose the data
|
20 |
df_zip = df_zip.loc[:, '2000-01-31':].T.reset_index()
|
|
|
23 |
# Convert 'Date' to datetime
|
24 |
df_zip['Date'] = pd.to_datetime(df_zip['Date'])
|
25 |
|
26 |
+
# Plot the data for each ZIP code
|
27 |
+
fig.add_trace(go.Scatter(x=df_zip['Date'], y=df_zip['Price'], mode='lines', name=str(zip_code)))
|
28 |
|
29 |
# Update plot layout
|
30 |
fig.update_layout(title=f'Housing Prices in {state}',
|
31 |
xaxis_title='Date',
|
32 |
yaxis_title='Price')
|
33 |
+
|
34 |
return fig
|
35 |
|
36 |
iface = gr.Interface(fn=plot_real_estate,
|
37 |
+
inputs=[gr.components.Textbox(label="State (e.g., 'NJ' for New Jersey)")],
|
38 |
outputs=gr.Plot())
|
39 |
|
40 |
iface.launch(share=False, debug=True)
|