DavidHosp's picture
update app.py
00b531e
raw
history blame
1.57 kB
import matplotlib.pyplot as plt
import io
from PIL import Image
import pickle
import pandas as pd
import gradio as gr
import gradio as gr
import pandas as pd
import joblib
# Cargar el modelo de pron贸stico
model = joblib.load('modelo_rf.pkl')
# Definir las opciones para 'Borough' y 'Tipo_de_taxi'
borough_options = ['Bronx', 'Brooklyn', 'Manhattan', 'Staten Island']
taxi_options = ['yellow', 'green']
# Funci贸n para realizar las predicciones
def make_predictions(borough, taxi, years):
# Crear un DataFrame con las caracter铆sticas de entrada
df = pd.DataFrame({'borough': [borough], 'Tipo_de_taxi': [taxi]})
# Generar los a帽os de pron贸stico
years_range = pd.date_range(start='today', periods=years, freq='Y').year
# Realizar las predicciones para cada a帽o de pron贸stico
predictions = []
for year in years_range:
df['Date'] = pd.to_datetime(year, format='%Y')
prediction = model.predict(df)
predictions.append(prediction)
# Crear un DataFrame con los a帽os y las predicciones
result_df = pd.DataFrame({'Year': years_range, 'Prediction': predictions})
return result_df
# Interfaz de Gradio
iface = gr.Interface(
fn=make_predictions,
inputs=[
gr.inputs.Dropdown(choices=borough_options, label='Borough'),
gr.inputs.Dropdown(choices=taxi_options, label='Tipo_de_taxi'),
gr.inputs.Slider(minimum=1, maximum=10, default=5, label='Years')
],
outputs=gr.outputs.Dataframe(headers=['Year', 'Prediction'])
)
# Ejecutar la interfaz de Gradio
iface.launch()