Spaces:
Runtime error
Runtime error
barbieheimer
commited on
Commit
•
6a8d218
1
Parent(s):
7922666
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,19 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
|
4 |
-
|
5 |
-
def __init__(self, model_name: str):
|
6 |
-
self.model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
-
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
-
self.pipeline = pipeline(
|
9 |
-
"text-classification",
|
10 |
-
model=self.model,
|
11 |
-
tokenizer=self.tokenizer,
|
12 |
-
return_all_scores=True,
|
13 |
-
)
|
14 |
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
"Anger 😭": pred[3]["score"],
|
23 |
-
}
|
24 |
-
return result
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
iface = gr.Interface(
|
30 |
-
fn=model.predict,
|
31 |
-
inputs=gr.inputs.Textbox(
|
32 |
-
lines=3,
|
33 |
-
placeholder="Type a phrase that has some emotion",
|
34 |
-
label="Input Text",
|
35 |
-
),
|
36 |
-
outputs="label",
|
37 |
-
title="Emotion Classification",
|
38 |
-
examples=[
|
39 |
-
"I get so down when I'm alone",
|
40 |
-
"I believe that today everything will work out",
|
41 |
-
"It was so dark there I was afraid to go",
|
42 |
-
"I loved the gift you gave me",
|
43 |
-
"I was very surprised by your presentation.",
|
44 |
-
],
|
45 |
-
)
|
46 |
-
|
47 |
-
iface.launch()
|
48 |
-
|
49 |
-
|
50 |
-
if __name__ == "__main__":
|
51 |
-
main()
|
|
|
1 |
+
# here are some examples for sadness, joy, anger, and optimism.
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
model = "models/barbieheimer/MND_TweetEvalBert_model"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def predict(prompt):
|
7 |
+
completion = classifier(prompt)
|
8 |
+
return completion[0]["label"], completion[0]["score"]
|
9 |
|
10 |
+
examples = [
|
11 |
+
["The movie was a bummer."],
|
12 |
+
["I cannot wait to watch all these movies!"],
|
13 |
+
["The ending of the movie really irks me, gives me the ick fr."],
|
14 |
+
["The protagonist seems to have a lot of hope...."]
|
15 |
+
]
|
|
|
|
|
|
|
16 |
|
17 |
+
gr.Interface.load("models/barbieheimer/MND_TweetEvalBert_model", fn=predict, title="Sentiment Analysis", examples=examples,
|
18 |
+
inputs=gr.inputs.Textbox(lines=5, label="Paste an Article here."),
|
19 |
+
outputs=[gr.outputs.Textbox(label="Label"),gr.outputs.Textbox(label="Score")],).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|