Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
from google.cloud import language_v1
|
|
|
3 |
|
4 |
def print_result(annotations):
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
def analyze_sentiment(texts): # Modify for text input (texts will be a string)
|
8 |
-
client = language_v1.LanguageServiceClient()
|
9 |
document = language_v1.Document(content=texts, type_=language_v1.Document.Type.PLAIN_TEXT)
|
10 |
annotations = client.analyze_sentiment(request={"document": document})
|
|
|
11 |
return annotations
|
12 |
|
13 |
st.title("Sentiment Analysis App")
|
|
|
1 |
import streamlit as st
|
2 |
from google.cloud import language_v1
|
3 |
+
from google.oauth2 import service_account
|
4 |
|
5 |
def print_result(annotations):
|
6 |
+
score = annotations.document_sentiment.score
|
7 |
+
magnitude = annotations.document_sentiment.magnitude
|
8 |
+
|
9 |
+
for index, sentence in enumerate(annotations.sentences):
|
10 |
+
sentence_sentiment = sentence.sentiment.score
|
11 |
+
st.write(f"Sentence {index} has a sentiment score of {sentence_sentiment}")
|
12 |
+
|
13 |
+
st.write(f"Overall Sentiment: score of {score} with magnitude of {magnitude}")
|
14 |
+
|
15 |
+
def analyze_sentiment(texts):
|
16 |
+
# Load credentials directly from secrets
|
17 |
+
credentials_info = st.secrets["GOOGLE_APPLICATION_CREDENTIALS"]
|
18 |
+
credentials = service_account.Credentials.from_service_account_info(credentials_info)
|
19 |
+
|
20 |
+
client = language_v1.LanguageServiceClient(credentials=credentials)
|
21 |
|
|
|
|
|
22 |
document = language_v1.Document(content=texts, type_=language_v1.Document.Type.PLAIN_TEXT)
|
23 |
annotations = client.analyze_sentiment(request={"document": document})
|
24 |
+
|
25 |
return annotations
|
26 |
|
27 |
st.title("Sentiment Analysis App")
|