File size: 1,150 Bytes
a775350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# here are some examples for sadness, joy, anger, and optimism.
import gradio as gr
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import pipeline

tokenizer = AutoTokenizer.from_pretrained("barbieheimer/MND_TweetEvalBert_model")
model = AutoModelForSequenceClassification.from_pretrained("barbieheimer/MND_TweetEvalBert_model")

# We can now use the model in the pipeline.
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)

def predict(prompt):
    completion = classifier(prompt)
    return completion[0]["label"], completion[0]["score"]

examples = [
    ["The movie was a bummer."],
    ["I cannot wait to watch all these movies!"],
    ["The ending of the movie really irks me, gives me the ick fr."],
    ["The protagonist seems to have a lot of hope...."]
]

gr.Interface.load("models/barbieheimer/MND_TweetEvalBert_model", fn=predict, title="Sentiment Analysis", examples=examples,
    inputs=gr.inputs.Textbox(lines=5, label="Paste an Article here."),
    outputs=[gr.outputs.Textbox(label="Label"),gr.outputs.Textbox(label="Score")],).launch()