ynp3 commited on
Commit
da61dbd
·
verified ·
1 Parent(s): 6193433

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -5,9 +5,6 @@ from flair.models import TextClassifier
5
  from flair.data import Sentence
6
  import matplotlib.pyplot as plt
7
 
8
- # Load Flair model outside the function
9
- classifier = TextClassifier.load('en-sentiment')
10
-
11
  # Function to perform sentiment analysis using TextBlob model
12
  def textblob_sentiment(text):
13
  blob = TextBlob(text)
@@ -21,6 +18,7 @@ def vader_sentiment(text):
21
 
22
  # Function to perform sentiment analysis using Flair model
23
  def flair_sentiment(text):
 
24
  sentence = Sentence(text)
25
  classifier.predict(sentence)
26
  if sentence.labels[0].value == 'POSITIVE':
@@ -51,5 +49,4 @@ fig, ax = plt.subplots()
51
  ax.bar(['TextBlob', 'VADER', 'Flair'], [textblob_score, vader_score, flair_score])
52
  ax.axhline(y=0, color='gray', linestyle='--')
53
  ax.set_title('Sentiment Scores')
54
- st.pyplot(fig)
55
- plt.close(fig) # Close the figure to prevent memory leaks
 
5
  from flair.data import Sentence
6
  import matplotlib.pyplot as plt
7
 
 
 
 
8
  # Function to perform sentiment analysis using TextBlob model
9
  def textblob_sentiment(text):
10
  blob = TextBlob(text)
 
18
 
19
  # Function to perform sentiment analysis using Flair model
20
  def flair_sentiment(text):
21
+ classifier = TextClassifier.load('en-sentiment')
22
  sentence = Sentence(text)
23
  classifier.predict(sentence)
24
  if sentence.labels[0].value == 'POSITIVE':
 
49
  ax.bar(['TextBlob', 'VADER', 'Flair'], [textblob_score, vader_score, flair_score])
50
  ax.axhline(y=0, color='gray', linestyle='--')
51
  ax.set_title('Sentiment Scores')
52
+ st.pyplot(fig)