|
import gradio as gr |
|
import pandas as pd |
|
import plotly.express as px |
|
|
|
def plot_real_estate(state): |
|
|
|
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') |
|
|
|
|
|
df_state = df[df['State'] == state.upper()] |
|
|
|
|
|
zip_codes = df_state['RegionName'].unique() |
|
|
|
|
|
fig = px.Figure() |
|
|
|
|
|
for zip_code in zip_codes: |
|
df_zip = df_state[df_state['RegionName'] == zip_code] |
|
|
|
|
|
df_zip = df_zip.loc[:, '2000-01-31':].T.reset_index() |
|
df_zip.columns = ['Date', 'Price'] |
|
|
|
|
|
df_zip['Date'] = pd.to_datetime(df_zip['Date']) |
|
|
|
|
|
fig.add_scatter(x=df_zip['Date'], y=df_zip['Price'], mode='lines', name=str(zip_code)) |
|
|
|
|
|
fig.update_layout(title=f'Housing Prices in {state}', |
|
xaxis_title='Date', |
|
yaxis_title='Price') |
|
return fig |
|
|
|
iface = gr.Interface(fn=plot_real_estate, |
|
inputs=[gr.components.Textbox(label="State (e.g., NJ for New Jersey)")], |
|
outputs=gr.Plot()) |
|
|
|
iface.launch(share=False, debug=True) |