File size: 982 Bytes
6708408
 
 
c67ff1e
6708408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c240020
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
import gradio as gr
import pickle
import gzip
import surprise

# Comprimir el archivo pickle utilizando gzip
with open('modelo_recomendacion.pkl', 'rb') as f_in, gzip.open('archivo.modelo_recomendacion.gz', 'wb') as f_out:
    f_out.writelines(f_in)

# Cargar el modelo desde un archivo
with open('modelo_recomendacion.pkl', 'rb') as archivo:
    model = pickle.load(archivo)

def get_predictions(userId, id):
    predictions = model.predict(userId, id)

    if predictions.est >= 4:
        mensaje = "Muy recomendada"
    elif predictions.est >= 3 and predictions.est < 4:
        mensaje = "Recomendada"
    else:
        mensaje = f"No te la recomiendo ({predictions.est:.2f})"

    return mensaje

inputs = [
    gr.inputs.Textbox(label="User ID"),
    gr.inputs.Textbox(label="ID"),
]

output = gr.outputs.Textbox(label="Predicci贸n")

iface = gr.Interface(fn=get_predictions, inputs=inputs, outputs=output, title="Predicci贸n de recomendaci贸n de pel铆culas")
iface.launch()