dibend commited on
Commit
ae905a3
1 Parent(s): 49525d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -5,7 +5,7 @@ from sklearn.linear_model import LinearRegression
5
  import numpy as np
6
  from pandas.tseries.offsets import MonthEnd
7
 
8
- def plot_and_predict(zip, prediction_months):
9
  # Read and process the real estate data from Zillow
10
  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')
11
  df = df[df['RegionName'] == int(zip)]
@@ -14,6 +14,10 @@ def plot_and_predict(zip, prediction_months):
14
  df.columns = ['Date', 'Price']
15
  df['Date'] = pd.to_datetime(df['Date'])
16
 
 
 
 
 
17
  # Train linear regression model
18
  df['MonthsSinceStart'] = np.arange(len(df))
19
  X = df['MonthsSinceStart'].values.reshape(-1, 1)
@@ -59,10 +63,11 @@ interface = gr.Interface(
59
  fn=plot_and_predict,
60
  inputs=[
61
  gr.Textbox(label="ZIP Code"),
 
62
  gr.Slider(minimum=1, maximum=60, step=1, label="Prediction Months"),
63
  ],
64
  outputs="plot"
65
  )
66
 
67
  # Launch the app
68
- interface.launch(debug=True)
 
5
  import numpy as np
6
  from pandas.tseries.offsets import MonthEnd
7
 
8
+ def plot_and_predict(zip, start_date, prediction_months):
9
  # Read and process the real estate data from Zillow
10
  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')
11
  df = df[df['RegionName'] == int(zip)]
 
14
  df.columns = ['Date', 'Price']
15
  df['Date'] = pd.to_datetime(df['Date'])
16
 
17
+ # Filter data based on start date
18
+ start_date = pd.to_datetime(start_date)
19
+ df = df[df['Date'] >= start_date]
20
+
21
  # Train linear regression model
22
  df['MonthsSinceStart'] = np.arange(len(df))
23
  X = df['MonthsSinceStart'].values.reshape(-1, 1)
 
63
  fn=plot_and_predict,
64
  inputs=[
65
  gr.Textbox(label="ZIP Code"),
66
+ gr.Textbox(label="Start Date (YYYY-MM-DD)", placeholder="YYYY-MM-DD"),
67
  gr.Slider(minimum=1, maximum=60, step=1, label="Prediction Months"),
68
  ],
69
  outputs="plot"
70
  )
71
 
72
  # Launch the app
73
+ interface.launch()