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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -22
app.py CHANGED
@@ -2,34 +2,35 @@ 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
 
27
  # Streamlit UI
28
  st.title('Google Cloud NLP Entity Analyzer')
29
  user_input = st.text_area('Enter text to analyze', '')
30
 
31
  if st.button('Analyze'):
32
- st.write("Debug: Analyze button clicked")
33
  if user_input:
34
- st.write(f"Debug: User input received: {user_input}")
35
  sample_analyze_entities(user_input)
 
2
  from google.cloud import language_v1
3
  import os
4
 
5
+ # Your provided function
6
  def sample_analyze_entities(text_content):
7
+ client = language_v1.LanguageServiceClient()
8
+
9
+ type_ = language_v1.Document.Type.PLAIN_TEXT
10
+ language = "en"
11
+ document = {"content": text_content, "type_": type_, "language": language}
12
+ encoding_type = language_v1.EncodingType.UTF8
13
+
14
+ response = client.analyze_entities(request={"document": document, "encoding_type": encoding_type})
15
+
16
+ for entity in response.entities:
17
+ st.write(f"Representative name for the entity: {entity.name}")
18
+ st.write(f"Entity type: {language_v1.Entity.Type(entity.type_).name}")
19
+ st.write(f"Salience score: {entity.salience}")
20
+
21
+ for metadata_name, metadata_value in entity.metadata.items():
22
+ st.write(f"{metadata_name}: {metadata_value}")
23
+
24
+ for mention in entity.mentions:
25
+ st.write(f"Mention text: {mention.text.content}")
26
+ st.write(f"Mention type: {language_v1.EntityMention.Type(mention.type_).name}")
27
+
28
+ st.write(f"Language of the text: {response.language}")
29
 
30
  # Streamlit UI
31
  st.title('Google Cloud NLP Entity Analyzer')
32
  user_input = st.text_area('Enter text to analyze', '')
33
 
34
  if st.button('Analyze'):
 
35
  if user_input:
 
36
  sample_analyze_entities(user_input)