Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import text_hammer as th
|
| 4 |
+
from transformers import BertTokenizer, BertModel
|
| 5 |
+
|
| 6 |
+
name = "MiVaCod/mbart-neutralization"
|
| 7 |
+
tokenizer = BertTokenizer.from_pretrained(name)
|
| 8 |
+
model = BertModel.from_pretrained(name)
|
| 9 |
+
|
| 10 |
+
# Define a function to make predictions
|
| 11 |
+
def predict(texts):
|
| 12 |
+
# Tokenize and preprocess the new text
|
| 13 |
+
new_encodings = tokenizer(texts, truncation=True, padding=True, max_length=70, return_tensors='tf')
|
| 14 |
+
new_predictions = model(new_encodings)
|
| 15 |
+
# Make predictions
|
| 16 |
+
new_predictions = model(new_encodings)
|
| 17 |
+
new_labels_pred = tf.argmax(new_predictions.logits, axis=1)
|
| 18 |
+
new_labels_pred = new_labels_pred.numpy()[0]
|
| 19 |
+
|
| 20 |
+
labels_list = ["Negative 😠", "Positive 😍"]
|
| 21 |
+
emotion = labels_list[new_labels_pred]
|
| 22 |
+
return emotion
|
| 23 |
+
|
| 24 |
+
# Create a Gradio interface
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=predict,
|
| 27 |
+
inputs="text",
|
| 28 |
+
outputs=gr.outputs.Label(num_top_classes = 6), # Corrected output type
|
| 29 |
+
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."],
|
| 30 |
+
],
|
| 31 |
+
title="Rotten tomatoes classification",
|
| 32 |
+
description="Predict the class associated with a text."
|
| 33 |
+
)
|
| 34 |
+
# Launch the interfac
|
| 35 |
+
iface.launch()
|