Spaces:
Sleeping
Sleeping
Commit
·
8041b5b
1
Parent(s):
68988c7
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,15 @@ import json
|
|
| 2 |
import streamlit as st
|
| 3 |
from google.oauth2 import service_account
|
| 4 |
from google.cloud import language_v1
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Header and intro
|
| 8 |
st.title("Google Cloud NLP Entity Analyzer")
|
|
@@ -31,6 +39,7 @@ def sample_analyze_entities(text_content, your_query=""):
|
|
| 31 |
entities_list = []
|
| 32 |
for entity in response.entities:
|
| 33 |
entity_type_name = language_v1.Entity.Type(entity.type_).name
|
|
|
|
| 34 |
entity_details = {
|
| 35 |
"Name": entity.name,
|
| 36 |
"Type": entity_type_name,
|
|
@@ -53,6 +62,11 @@ def sample_analyze_entities(text_content, your_query=""):
|
|
| 53 |
st.write(f"**{key}:**")
|
| 54 |
st.write(value)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
st.write("----")
|
| 57 |
|
| 58 |
st.write(f"### Language of the text: {response.language}")
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from google.oauth2 import service_account
|
| 4 |
from google.cloud import language_v1
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
+
# Adding checkbox options for entity types
|
| 8 |
+
entity_types_to_show = ["PERSON", "ORGANIZATION", "EVENT"]
|
| 9 |
+
selected_types = st.multiselect('Select entity types to show:', entity_types_to_show)
|
| 10 |
+
|
| 11 |
+
# Function for querying Google Knowledge Graph API
|
| 12 |
+
def query_google_knowledge_graph(entity_name):
|
| 13 |
+
return {"info": "Knowledge Graph info for {}".format(entity_name)}
|
| 14 |
|
| 15 |
# Header and intro
|
| 16 |
st.title("Google Cloud NLP Entity Analyzer")
|
|
|
|
| 39 |
entities_list = []
|
| 40 |
for entity in response.entities:
|
| 41 |
entity_type_name = language_v1.Entity.Type(entity.type_).name
|
| 42 |
+
if entity_type_name in selected_types:
|
| 43 |
entity_details = {
|
| 44 |
"Name": entity.name,
|
| 45 |
"Type": entity_type_name,
|
|
|
|
| 62 |
st.write(f"**{key}:**")
|
| 63 |
st.write(value)
|
| 64 |
|
| 65 |
+
# Query Google Knowledge Graph API for each entity
|
| 66 |
+
kg_info = query_google_knowledge_graph(entity['Name'])
|
| 67 |
+
st.write("### Google Knowledge Graph Information")
|
| 68 |
+
st.write(kg_info)
|
| 69 |
+
|
| 70 |
st.write("----")
|
| 71 |
|
| 72 |
st.write(f"### Language of the text: {response.language}")
|