blazingbunny commited on
Commit
5ee65ad
·
verified ·
1 Parent(s): 5731adf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -38
app.py CHANGED
@@ -1,38 +1 @@
1
- import streamlit as st
2
- from google.cloud import language_v1
3
- from google.oauth2 import service_account
4
- import json
5
-
6
- def print_result(annotations):
7
- score = annotations.document_sentiment.score
8
- magnitude = annotations.document_sentiment.magnitude
9
-
10
- for index, sentence in enumerate(annotations.sentences):
11
- sentence_sentiment = sentence.sentiment.score
12
- st.write(f"Sentence {index} has a sentiment score of {sentence_sentiment}")
13
-
14
- st.write(f"Overall Sentiment: score of {score} with magnitude of {magnitude}")
15
-
16
- def analyze_sentiment(texts):
17
- # Load credentials directly from secrets (load as JSON)
18
- credentials_info = json.loads(st.secrets["GOOGLE_APPLICATION_CREDENTIALS"])
19
- credentials = service_account.Credentials.from_service_account_info(credentials_info)
20
-
21
- client = language_v1.LanguageServiceClient(credentials=credentials)
22
-
23
- document = language_v1.Document(content=texts, type_=language_v1.Document.Type.PLAIN_TEXT)
24
- annotations = client.analyze_sentiment(request={"document": document})
25
-
26
- return annotations
27
-
28
- st.title("Sentiment Analysis App")
29
- st.write("Enter some text to analyze its sentiment:")
30
-
31
- text_input = st.text_area("Text to analyze", height=200)
32
-
33
- if st.button("Analyze Sentiment"):
34
- if text_input:
35
- annotations = analyze_sentiment(text_input)
36
- print_result(annotations)
37
- else:
38
- st.warning("Please enter some text.")
 
1
+ st.write(st.secrets["GOOGLE_APPLICATION_CREDENTIALS"])