Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow_hub as hub
|
| 2 |
+
import pickle
|
| 3 |
+
import sklearn
|
| 4 |
+
|
| 5 |
+
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
|
| 6 |
+
|
| 7 |
+
with open('./model.pck', 'rb') as f:
|
| 8 |
+
model = pickle.load(f)
|
| 9 |
+
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
def convert(text):
|
| 13 |
+
#Se genera el embedding del texto
|
| 14 |
+
text_embed = embed([text])
|
| 15 |
+
#El modelo hace su predicción
|
| 16 |
+
prediction = model.predict_proba(text_embed).flatten()
|
| 17 |
+
#Se devuelve el percentaje que el modelo ha predicho para cada etiqueta
|
| 18 |
+
return {"ham": float(prediction[0]), "spam" : float(prediction[1])}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=convert,
|
| 23 |
+
inputs="text",
|
| 24 |
+
outputs="label",
|
| 25 |
+
examples=["I will help you win the lottery, my friend", "Please, darling, could you pick up the kids from school today?"],
|
| 26 |
+
title="Ham or spam?",
|
| 27 |
+
description="Copy the text message you just received and we'll let you know if it is ham or spam",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface.launch()
|