Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
from google.cloud import language_v1
|
3 |
from google.oauth2 import service_account
|
4 |
-
import json
|
5 |
|
6 |
-
#
|
|
|
7 |
|
8 |
def print_result(annotations):
|
9 |
# Overall Sentiment
|
@@ -30,9 +30,7 @@ def print_result(annotations):
|
|
30 |
st.write(f" * Magnitude: {entity.sentiment.magnitude}")
|
31 |
st.write(f" * Salience: {entity.salience}")
|
32 |
|
33 |
-
def analyze_sentiment(texts):
|
34 |
-
# ... (Your authentication code)
|
35 |
-
|
36 |
client = language_v1.LanguageServiceClient(credentials=credentials)
|
37 |
|
38 |
# Include options for entity analysis
|
@@ -47,8 +45,8 @@ st.write("Enter some text to analyze its sentiment:")
|
|
47 |
text_input = st.text_area("Text to analyze", height=200)
|
48 |
|
49 |
if st.button("Analyze Sentiment"):
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
1 |
import streamlit as st
|
2 |
from google.cloud import language_v1
|
3 |
from google.oauth2 import service_account
|
|
|
4 |
|
5 |
+
# Load Google Cloud credentials
|
6 |
+
credentials = service_account.Credentials.from_service_account_file(json.loads(st.secrets["GOOGLE_APPLICATION_CREDENTIALS"]))
|
7 |
|
8 |
def print_result(annotations):
|
9 |
# Overall Sentiment
|
|
|
30 |
st.write(f" * Magnitude: {entity.sentiment.magnitude}")
|
31 |
st.write(f" * Salience: {entity.salience}")
|
32 |
|
33 |
+
def analyze_sentiment(texts, credentials):
|
|
|
|
|
34 |
client = language_v1.LanguageServiceClient(credentials=credentials)
|
35 |
|
36 |
# Include options for entity analysis
|
|
|
45 |
text_input = st.text_area("Text to analyze", height=200)
|
46 |
|
47 |
if st.button("Analyze Sentiment"):
|
48 |
+
if text_input:
|
49 |
+
annotations = analyze_sentiment(text_input, credentials)
|
50 |
+
print_result(annotations)
|
51 |
+
else:
|
52 |
+
st.warning("Please enter some text.")
|