imalexianne commited on
Commit
2b96d10
1 Parent(s): b3fe5ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -23
app.py CHANGED
@@ -1,32 +1,42 @@
1
  import os
2
  import gradio as gr
 
3
  from transformers import AutoTokenizer, AutoModel
4
  from scipy.special import softmax
5
- from huggingface_hub import login
6
 
7
- # Load environment variables
8
- from dotenv import load_dotenv
 
 
 
 
 
 
 
9
  load_dotenv()
10
-
11
  login(os.getenv("access_token"))
12
 
 
13
  # Requirements
 
14
  model_path = "imalexianne/distilbert-base-uncased"
15
- # tokenizer = AutoTokenizer.from_pretrained(model_path)
16
  tokenizer = AutoTokenizer.from_pretrained(model_path)
17
 
18
- model = AutoModel.from_pretrained(model_path)
 
 
 
19
 
20
- # Preprocessing function
21
  def preprocess(text):
22
  new_text = []
23
- for x in text.split(" "):
24
- x = "@user" if x.startswith("@") and len(x) > 1 else x
25
- x = "http" if x.startswith("http") else x
26
- new_text.append(x)
27
  return " ".join(new_text)
28
 
29
- # Function to process the input and return prediction
30
  def sentiment_analysis(text):
31
  text = preprocess(text)
32
 
@@ -41,14 +51,15 @@ def sentiment_analysis(text):
41
 
42
  return scores
43
 
44
- # Gradio app interface
45
- app = gr.Interface(
46
- fn=sentiment_analysis,
47
- inputs=gr.Textbox("Write your text here..."),
48
- outputs="label",
49
- title="Sentiment Analysis of Tweets on COVID-19 Vaccines",
50
- description="Sentiment Analysis of text based on tweets about COVID-19 Vaccines using a fine-tuned 'distilbert-base-uncased' model",
51
- examples=[["Covid vaccination has no positive impact"]]
52
- )
53
-
54
- app.launch()
 
 
1
  import os
2
  import gradio as gr
3
+ import numpy as np
4
  from transformers import AutoTokenizer, AutoModel
5
  from scipy.special import softmax
 
6
 
7
+ import gradio as gr
8
+ import numpy as np
9
+ import pandas as pd
10
+ import pickle
11
+ import transformers
12
+ from transformers import AutoTokenizer, AutoConfig,AutoModelForSequenceClassification,TFAutoModelForSequenceClassification, pipeline
13
+ from scipy.special import softmax
14
+ from dotenv import load_dotenv, dotenv_values
15
+ from huggingface_hub import login
16
  load_dotenv()
 
17
  login(os.getenv("access_token"))
18
 
19
+
20
  # Requirements
21
+ # huggingface_token = "" # Replace with your actual token
22
  model_path = "imalexianne/distilbert-base-uncased"
 
23
  tokenizer = AutoTokenizer.from_pretrained(model_path)
24
 
25
+ # tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
26
+ # tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased", revision="main")
27
+ config = AutoConfig.from_pretrained(model_path)
28
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
29
 
30
+ # Preprocessessing function
31
  def preprocess(text):
32
  new_text = []
33
+ for t in text.split(" "):
34
+ t = "@user" if t.startswith("@") and len(t) > 1 else t
35
+ t = "http" if t.startswith("http") else t
36
+ new_text.append(t)
37
  return " ".join(new_text)
38
 
39
+ # ---- Function to process the input and return prediction
40
  def sentiment_analysis(text):
41
  text = preprocess(text)
42
 
 
51
 
52
  return scores
53
 
54
+
55
+ # ---- Gradio app interface
56
+ app = gr.Interface(fn = sentiment_analysis,
57
+ inputs = gr.Textbox("Write your text here..."),
58
+ outputs = "label",
59
+ title = "Sentiment Analysis of Tweets on COVID-19 Vaccines",
60
+ description = "Sentiment Analysis of text based on tweets about COVID-19 Vaccines using a fine-tuned 'distilbert-base-uncased' model",
61
+
62
+ examples = [["Covid vaccination has no positive impact"]]
63
+ )
64
+
65
+ app.launch()