Spaces:
Build error
Build error
Commit
·
53bca84
1
Parent(s):
f3aae5e
Update app.py
Browse files
app.py
CHANGED
@@ -2,34 +2,35 @@ import streamlit as st
|
|
2 |
from google.cloud import language_v1
|
3 |
import os
|
4 |
|
5 |
-
# Your
|
6 |
def sample_analyze_entities(text_content):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
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)
|