Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,27 @@
|
|
1 |
import os
|
2 |
os.environ["STREAMLIT_NO_ALT"] = "true"
|
3 |
|
4 |
-
# Install necessary packages
|
5 |
-
import subprocess
|
6 |
-
subprocess.call(["pip", "install", "textblob"])
|
7 |
-
subprocess.call(["pip", "install", "vadersentiment"])
|
8 |
-
subprocess.call(["pip", "install", "flair"])
|
9 |
-
|
10 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
from textblob import TextBlob
|
12 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
13 |
from flair.models import TextClassifier
|
14 |
from flair.data import Sentence
|
15 |
-
import matplotlib.pyplot as plt
|
16 |
|
17 |
# Function to perform sentiment analysis using TextBlob model
|
18 |
def textblob_sentiment(text):
|
@@ -58,4 +67,4 @@ fig, ax = plt.subplots()
|
|
58 |
ax.bar(['TextBlob', 'VADER', 'Flair'], [textblob_score, vader_score, flair_score])
|
59 |
ax.axhline(y=0, color='gray', linestyle='--')
|
60 |
ax.set_title('Sentiment Scores')
|
61 |
-
st.pyplot(fig)
|
|
|
1 |
import os
|
2 |
os.environ["STREAMLIT_NO_ALT"] = "true"
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import streamlit as st
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
# Install dependencies
|
8 |
+
st.write("Installing dependencies...")
|
9 |
+
streamlit_deps = """
|
10 |
+
streamlit
|
11 |
+
textblob
|
12 |
+
vadersentiment
|
13 |
+
flair
|
14 |
+
matplotlib
|
15 |
+
""".strip().split('\n')
|
16 |
+
|
17 |
+
for lib in streamlit_deps:
|
18 |
+
os.system(f"pip install {lib}")
|
19 |
+
|
20 |
+
# Now you can import them
|
21 |
from textblob import TextBlob
|
22 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
23 |
from flair.models import TextClassifier
|
24 |
from flair.data import Sentence
|
|
|
25 |
|
26 |
# Function to perform sentiment analysis using TextBlob model
|
27 |
def textblob_sentiment(text):
|
|
|
67 |
ax.bar(['TextBlob', 'VADER', 'Flair'], [textblob_score, vader_score, flair_score])
|
68 |
ax.axhline(y=0, color='gray', linestyle='--')
|
69 |
ax.set_title('Sentiment Scores')
|
70 |
+
st.pyplot(fig)
|