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