Shiko07 commited on
Commit
0a05aa7
1 Parent(s): c25eb36
Files changed (2) hide show
  1. app.py +55 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %pip install gradio
2
+ %pip install transformers
3
+
4
+ import gradio as gr
5
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
6
+ import torch
7
+ from huggingface_hub import notebook_login
8
+
9
+
10
+
11
+ # Load the Pre-trained Model and Tokenizer:
12
+
13
+ model_name = "Shiko07/tuned_test_trainer-bert-base-uncased"
14
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+
17
+ #Defining the Gradio Interface:
18
+
19
+ def predict_sentiment(text):
20
+ inputs = tokenizer(text, return_tensors="pt")
21
+ outputs = model(**inputs)
22
+ predicted_class = torch.argmax(outputs.logits, dim=1).item()
23
+ return {0: "Negative", 1: "Neutral", 2: "Positive"}[predicted_class]
24
+
25
+ #Creating Gradio interface:
26
+
27
+ custom_css = """
28
+ .gradio {
29
+ background-color: #0074D9; /* Change background color to blue */
30
+ }
31
+ """
32
+ # predict_sentiment function
33
+
34
+
35
+ interface = gr.Interface(
36
+ fn=predict_sentiment,
37
+ inputs=gr.Textbox(lines=3, label="Enter your text:"),
38
+ outputs="text",
39
+ # theme="custom_css",
40
+ title="Marrakech Sentiment Analysis App",
41
+ description="An app for sentiment analysis for Tweet posts on covid 19 vaccine.",
42
+ css=custom_css,
43
+ examples = [ ["Vaccine misinformation is harmful."],
44
+ ["I'm hopeful about the vaccine."],
45
+ ["Second dose excitement."],
46
+ ["I'm worried about vaccine side effects."],
47
+ ["Vaccine distribution updates are available."],
48
+ ["Vaccine distribution is too slow."],
49
+ ["I'm gathering information about the vaccine."]
50
+ ]
51
+
52
+
53
+ )
54
+
55
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ numpy
4
+ scipy