Spaces:
Runtime error
Runtime error
File size: 915 Bytes
0cce3d6 fd1b94b b2e4146 a52b36f b2e4146 |
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 |
import tensorflow_hub as hub
import pickle
import sklearn
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
with open('./model.pck', 'rb') as f:
model = pickle.load(f)
import gradio as gr
def convert(text):
#Se genera el embedding del texto
text_embed = embed([text])
#El modelo hace su predicción
prediction = model.predict_proba(text_embed).flatten()
#Se devuelve el percentaje que el modelo ha predicho para cada etiqueta
return {"ham": float(prediction[0]), "spam" : float(prediction[1])}
iface = gr.Interface(
fn=convert,
inputs="text",
outputs="label",
examples=["I will help you win the lottery, my friend", "Please, darling, could you pick up the kids from school today?"],
title="Ham or spam?",
description="Copy and paste the text message you just received and we'll let you know if it is ham or spam",
)
iface.launch() |