blazingbunny commited on
Commit
f3aae5e
·
1 Parent(s): e6dc0b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,23 +1,26 @@
1
  import streamlit as st
 
2
  import os
3
 
4
- # Read API key if stored as an env variable
5
- api_key = os.environ.get("GOOGLE_API_KEY")
6
-
7
- # Your existing function
8
  def sample_analyze_entities(text_content):
9
  st.write("Debug: Entered sample_analyze_entities")
10
  try:
11
- # Placeholder: Your existing code to make Google Cloud NLP API call goes here
 
 
 
 
 
 
12
  st.write("Debug: Making API call...")
13
 
14
- # Example: (Replace this with your actual API call)
15
- # response = client.analyze_entities(...)
16
-
17
  st.write("Debug: API call completed.")
18
 
19
- # Placeholder: Process the response and display output
20
- # st.write(response)
21
  except Exception as e:
22
  st.write(f"Debug: An error occurred: {e}")
23
 
 
1
  import streamlit as st
2
+ from google.cloud import language_v1
3
  import os
4
 
5
+ # Your existing function (replace this part with your actual code)
 
 
 
6
  def sample_analyze_entities(text_content):
7
  st.write("Debug: Entered sample_analyze_entities")
8
  try:
9
+ client = language_v1.LanguageServiceClient()
10
+
11
+ type_ = language_v1.Document.Type.PLAIN_TEXT
12
+ language = "en"
13
+ document = {"content": text_content, "type_": type_, "language": language}
14
+ encoding_type = language_v1.EncodingType.UTF8
15
+
16
  st.write("Debug: Making API call...")
17
 
18
+ response = client.analyze_entities(request={"document": document, "encoding_type": encoding_type})
19
+
 
20
  st.write("Debug: API call completed.")
21
 
22
+ for entity in response.entities:
23
+ st.write(f"Entity: {entity.name}, Type: {language_v1.Entity.Type(entity.type_).name}, Salience: {entity.salience}")
24
  except Exception as e:
25
  st.write(f"Debug: An error occurred: {e}")
26