Spaces:
Runtime error
Runtime error
File size: 1,569 Bytes
09f6d5c 00b531e 09f6d5c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
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() |