MND_Tweet_Space2 / legacy_ver.py
barbieheimer's picture
Create legacy_ver.py
a775350
# 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()