Spaces:
Runtime error
Runtime error
Mrredborne
commited on
Commit
•
dac06bf
1
Parent(s):
428d491
app:init
Browse files- app.py +42 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
from huggingface_hub import notebook_login
|
5 |
+
|
6 |
+
|
7 |
+
notebook_login()
|
8 |
+
|
9 |
+
model_name = "Shiko07/tuned_test_trainer-bert-base-uncased"
|
10 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
+
|
13 |
+
def predict_sentiment(text):
|
14 |
+
inputs = tokenizer(text, return_tensors="pt")
|
15 |
+
outputs = model(**inputs)
|
16 |
+
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
17 |
+
return {0: "Negative", 1: "Neutral", 2: "Positive"}[predicted_class]
|
18 |
+
|
19 |
+
custom_css = """
|
20 |
+
.gradio {
|
21 |
+
background-color: #0074D9; /* Change background color to blue */
|
22 |
+
}
|
23 |
+
"""
|
24 |
+
|
25 |
+
# predict_sentiment function
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=predict_sentiment,
|
28 |
+
inputs=gr.Textbox(lines=3, label="Enter your text:"),
|
29 |
+
outputs="text",
|
30 |
+
title="Marrakech Sentiment Analysis App",
|
31 |
+
description="An app for sentiment analysis for Tweet posts on covid 19 vaccine.",
|
32 |
+
css=custom_css,
|
33 |
+
examples = [ ["Vaccine misinformation is harmful."],
|
34 |
+
["I'm hopeful about the vaccine."],
|
35 |
+
["Second dose excitement."],
|
36 |
+
["I'm worried about vaccine side effects."],
|
37 |
+
["Vaccine distribution updates are available."],
|
38 |
+
["Vaccine distribution is too slow."],
|
39 |
+
["I'm gathering information about the vaccine."]
|
40 |
+
]
|
41 |
+
)
|
42 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
3 |
+
numpy
|