imalexianne commited on
Commit
d66b74a
1 Parent(s): a05980a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -1,4 +1,9 @@
1
  import os
 
 
 
 
 
2
  import gradio as gr
3
  import numpy as np
4
  import pandas as pd
@@ -7,21 +12,22 @@ import transformers
7
  from transformers import AutoTokenizer, AutoConfig,AutoModelForSequenceClassification,TFAutoModelForSequenceClassification, pipeline
8
  from scipy.special import softmax
9
  from dotenv import load_dotenv, dotenv_values
10
- # from huggingface_hub import login
11
-
12
  from huggingface_hub import login
13
-
14
- # notebook_login()
15
  load_dotenv()
16
  login(os.getenv("access_token"))
 
 
17
  # Requirements
 
18
  model_path = "imalexianne/distilbert-base-uncased"
 
19
 
20
- tokenizer = AutoTokenizer.from_pretrained(model_path, revision="main")
21
- config = AutoConfig.from_pretrained(model_path, revision="main")
22
- model = AutoModelForSequenceClassification.from_pretrained(model_path, revision="main")
 
23
 
24
- # Preprocess text (username and link placeholders)
25
  def preprocess(text):
26
  new_text = []
27
  for x in text.split(" "):
@@ -38,22 +44,22 @@ def sentiment_analysis(text):
38
  output = model(**encoded_input)
39
  scores_ = output[0][0].detach().numpy()
40
  scores_ = softmax(scores_)
41
-
42
  # Format output dict of scores
43
  labels = ["Negative", "Neutral", "Positive"]
44
  scores = {l:float(s) for (l,s) in zip(labels, scores_) }
45
-
46
  return scores
47
 
48
 
49
  # ---- Gradio app interface
50
  app = gr.Interface(fn = sentiment_analysis,
51
- inputs = gr.Textbox("Write here"),
52
  outputs = "label",
53
  title = "Sentiment Analysis of Tweets on COVID-19 Vaccines",
54
  description = "Sentiment Analysis of text based on tweets about COVID-19 Vaccines using a fine-tuned 'distilbert-base-uncased' model",
55
-
56
  examples = [["Covid vaccination has no positive impact"]]
57
  )
58
 
59
- app.launch(share=True)
 
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
 
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 x in text.split(" "):
 
44
  output = model(**encoded_input)
45
  scores_ = output[0][0].detach().numpy()
46
  scores_ = softmax(scores_)
47
+
48
  # Format output dict of scores
49
  labels = ["Negative", "Neutral", "Positive"]
50
  scores = {l:float(s) for (l,s) in zip(labels, scores_) }
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()