Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,17 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import tensorflow as tf
|
| 3 |
from transformers import BertTokenizer, BertModel
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
new_predictions = model(new_encodings)
|
| 16 |
-
new_labels_pred = tf.argmax(new_predictions.logits, axis=1)
|
| 17 |
-
new_labels_pred = new_labels_pred.numpy()[0]
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Create a Gradio interface
|
| 24 |
-
iface = gr.Interface(
|
| 25 |
-
fn=predict,
|
| 26 |
-
inputs="text",
|
| 27 |
-
outputs=gr.outputs.Label(num_top_classes = 6), # Corrected output type
|
| 28 |
-
examples=[["the rock is destined to be the 21st century's new conan and that he's going to make a splash even greater than arnold schwarzenegger , jean-claud van damme or steven segal."],
|
| 29 |
-
],
|
| 30 |
-
title="Rotten tomatoes classification",
|
| 31 |
-
description="Predict the class associated with a text."
|
| 32 |
-
)
|
| 33 |
-
# Launch the interfac
|
| 34 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import BertTokenizer, BertModel
|
| 2 |
+
import gradio as grad
|
| 3 |
|
| 4 |
+
model_name = "MiVaCod/rotten"
|
| 5 |
+
text2text_tkn= BertTokenizer.from_pretrained(model_name)
|
| 6 |
+
mdl = BertModel.from_pretrained(model_name)
|
| 7 |
|
| 8 |
+
def text2text_paraphrase(sentence1):
|
| 9 |
+
inp1 = sentence1
|
| 10 |
+
enc = text2text_tkn(inp1, return_tensors="pt")
|
| 11 |
+
tokens = mdl.generate(**enc)
|
| 12 |
+
response=text2text_tkn.batch_decode(tokens)
|
| 13 |
+
return response
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
sent1=grad.Textbox(lines=1, label="Review", placeholder="Introduce la review de una película.")
|
| 16 |
+
out=gr.outputs.Label(num_top_classes=1)
|
| 17 |
+
grad.Interface(text2text_paraphrase, inputs=sent1, outputs=out).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|