Spaces:
Build error
Build error
Commit
·
bc4e0d2
1
Parent(s):
a88adef
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ entity_types_to_show = [
|
|
9 |
]
|
10 |
selected_types = st.multiselect('Select entity types to show:', entity_types_to_show)
|
11 |
|
12 |
-
|
13 |
# Header and intro
|
14 |
st.title("Google Cloud NLP Entity Analyzer")
|
15 |
st.write("## Introduction to the Knowledge Graph API")
|
@@ -44,38 +43,39 @@ def sample_analyze_entities(text_content, your_query=""):
|
|
44 |
# Create an empty list to hold the results
|
45 |
entities_list = []
|
46 |
|
47 |
-
# ... (rest of your code above)
|
48 |
-
|
49 |
for entity in response.entities:
|
50 |
entity_type_name = language_v1.Entity.Type(entity.type_).name
|
51 |
if not selected_types or entity_type_name in selected_types:
|
52 |
-
entity_details
|
53 |
-
"Name": entity.name,
|
54 |
-
"Type": entity_type_name,
|
55 |
-
"Salience Score": entity.salience,
|
56 |
-
"Metadata": entity.metadata,
|
57 |
-
"Mentions": [mention.text.content for mention in entity.mentions]
|
58 |
-
}
|
59 |
-
entities_list.append(entity_details)
|
60 |
-
|
61 |
-
# ... (rest of your code below)
|
62 |
|
|
|
63 |
|
|
|
64 |
if your_query:
|
65 |
-
st.write(f"We found {len(entities_list)} results for your query of **{your_query}**")
|
66 |
else:
|
67 |
-
st.write(
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
st.write(f"
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# User input for text analysis
|
81 |
user_input = st.text_area("Enter text to analyze")
|
|
|
9 |
]
|
10 |
selected_types = st.multiselect('Select entity types to show:', entity_types_to_show)
|
11 |
|
|
|
12 |
# Header and intro
|
13 |
st.title("Google Cloud NLP Entity Analyzer")
|
14 |
st.write("## Introduction to the Knowledge Graph API")
|
|
|
43 |
# Create an empty list to hold the results
|
44 |
entities_list = []
|
45 |
|
|
|
|
|
46 |
for entity in response.entities:
|
47 |
entity_type_name = language_v1.Entity.Type(entity.type_).name
|
48 |
if not selected_types or entity_type_name in selected_types:
|
49 |
+
# Your existing code for creating and populating the entity_details dictionary...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
entities_list.append(entity_details) # Append the dictionary to the list
|
52 |
|
53 |
+
# Streamlit UI
|
54 |
if your_query:
|
55 |
+
st.write(f"### We found {len(entities_list)} results for your query of **{your_query}**")
|
56 |
else:
|
57 |
+
st.write("### We found results for your query")
|
58 |
+
|
59 |
+
st.write("----")
|
60 |
+
|
61 |
+
for i, entity in enumerate(entities_list):
|
62 |
+
st.write(f"Relevance Score: {entity.get('Salience Score', 'N/A')} \t {i+1} of {len(entities_list)}")
|
63 |
+
|
64 |
+
# Display all key-value pairs in the entity dictionary
|
65 |
+
for key, value in entity.items():
|
66 |
+
if value:
|
67 |
+
st.write(f"**{key}:**")
|
68 |
+
if isinstance(value, (list, dict)):
|
69 |
+
try:
|
70 |
+
st.json(value)
|
71 |
+
except Exception as e:
|
72 |
+
st.write(f"Error while displaying JSON: {e}")
|
73 |
+
else:
|
74 |
+
st.write(value)
|
75 |
+
|
76 |
+
st.write("----")
|
77 |
+
|
78 |
+
st.write(f"### Language of the text: {response.language}")
|
79 |
|
80 |
# User input for text analysis
|
81 |
user_input = st.text_area("Enter text to analyze")
|