MiVaCod commited on
Commit
5a39616
·
verified ·
1 Parent(s): d45f2b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -30
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
- name = "MiVaCod/mbart-neutralization"
6
- tokenizer = BertTokenizer.from_pretrained(name)
7
- model = BertModel.from_pretrained(name)
8
 
9
- # Define a function to make predictions
10
- def predict(texts):
11
- # Tokenize and preprocess the new text
12
- new_encodings = tokenizer(texts, truncation=True, padding=True, max_length=70, return_tensors='tf')
13
- new_predictions = model(new_encodings)
14
- # Make predictions
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
- labels_list = ["Negative 😠", "Positive 😍"]
20
- emotion = labels_list[new_labels_pred]
21
- return emotion
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()