barbieheimer commited on
Commit
a775350
1 Parent(s): 7fc03a0

Create legacy_ver.py

Browse files

This is the old code I used for the app.

Files changed (1) hide show
  1. legacy_ver.py +26 -0
legacy_ver.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # here are some examples for sadness, joy, anger, and optimism.
2
+ import gradio as gr
3
+ # Load model directly
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
+ from transformers import pipeline
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("barbieheimer/MND_TweetEvalBert_model")
8
+ model = AutoModelForSequenceClassification.from_pretrained("barbieheimer/MND_TweetEvalBert_model")
9
+
10
+ # We can now use the model in the pipeline.
11
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
12
+
13
+ def predict(prompt):
14
+ completion = classifier(prompt)
15
+ return completion[0]["label"], completion[0]["score"]
16
+
17
+ examples = [
18
+ ["The movie was a bummer."],
19
+ ["I cannot wait to watch all these movies!"],
20
+ ["The ending of the movie really irks me, gives me the ick fr."],
21
+ ["The protagonist seems to have a lot of hope...."]
22
+ ]
23
+
24
+ gr.Interface.load("models/barbieheimer/MND_TweetEvalBert_model", fn=predict, title="Sentiment Analysis", examples=examples,
25
+ inputs=gr.inputs.Textbox(lines=5, label="Paste an Article here."),
26
+ outputs=[gr.outputs.Textbox(label="Label"),gr.outputs.Textbox(label="Score")],).launch()