Spaces:
Build error
Build error
Commit
·
e7ccb62
1
Parent(s):
bc4e0d2
Update app.py
Browse files
app.py
CHANGED
@@ -43,12 +43,28 @@ def sample_analyze_entities(text_content, your_query=""):
|
|
43 |
# Create an empty list to hold the results
|
44 |
entities_list = []
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
entities_list.append(entity_details) # Append the dictionary to the list
|
52 |
|
53 |
# Streamlit UI
|
54 |
if your_query:
|
@@ -73,7 +89,8 @@ def sample_analyze_entities(text_content, your_query=""):
|
|
73 |
else:
|
74 |
st.write(value)
|
75 |
|
76 |
-
st.write("----")
|
|
|
77 |
|
78 |
st.write(f"### Language of the text: {response.language}")
|
79 |
|
|
|
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 |
+
entity_details = {
|
50 |
+
"Name": entity.name,
|
51 |
+
"Type": entity_type_name,
|
52 |
+
"Salience Score": entity.salience,
|
53 |
+
"Metadata": [],
|
54 |
+
"Mentions": []
|
55 |
+
}
|
56 |
+
|
57 |
+
for metadata_name, metadata_value in entity.metadata.items():
|
58 |
+
entity_details["Metadata"].append({metadata_name: metadata_value})
|
59 |
+
|
60 |
+
for mention in entity.mentions:
|
61 |
+
entity_details["Mentions"].append({
|
62 |
+
"Text": mention.text.content,
|
63 |
+
"Type": language_v1.EntityMention.Type(mention.type_).name
|
64 |
+
})
|
65 |
+
|
66 |
+
entities_list.append(entity_details) # Append the dictionary to the list
|
67 |
|
|
|
68 |
|
69 |
# Streamlit UI
|
70 |
if your_query:
|
|
|
89 |
else:
|
90 |
st.write(value)
|
91 |
|
92 |
+
st.write("----") # Line separator
|
93 |
+
st.write(" ") # Extra line
|
94 |
|
95 |
st.write(f"### Language of the text: {response.language}")
|
96 |
|