Commit
·
c2b8ffb
1
Parent(s):
9502681
Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,29 @@ from google.oauth2 import service_account
|
|
3 |
from google.cloud import language_v1
|
4 |
import streamlit as st
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def sample_analyze_entities(text_content):
|
|
|
7 |
service_account_info = json.loads(st.secrets["google_nlp"])
|
|
|
|
|
8 |
credentials = service_account.Credentials.from_service_account_info(
|
9 |
service_account_info, scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
10 |
)
|
|
|
|
|
11 |
client = language_v1.LanguageServiceClient(credentials=credentials)
|
12 |
|
|
|
13 |
type_ = language_v1.Document.Type.PLAIN_TEXT
|
14 |
language = "en"
|
15 |
document = {"content": text_content, "type_": type_, "language": language}
|
@@ -48,21 +64,19 @@ def sample_analyze_entities(text_content):
|
|
48 |
st.write(f"**Name**: {entity['Name']}")
|
49 |
st.write(f"**Type**: {entity['Type']}")
|
50 |
st.write(f"**Salience Score**: {entity['Salience Score']}")
|
51 |
-
|
52 |
if entity["Metadata"]:
|
53 |
st.write("**Metadata**: ")
|
54 |
st.json(entity["Metadata"])
|
55 |
-
|
56 |
if entity["Mentions"]:
|
57 |
st.write("**Mentions**: ")
|
58 |
st.json(entity["Mentions"])
|
59 |
|
60 |
|
61 |
-
st.
|
62 |
-
user_input = st.text_area("Enter text to analyze", "Your text goes here")
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
st.write("Please enter some text to analyze.")
|
|
|
3 |
from google.cloud import language_v1
|
4 |
import streamlit as st
|
5 |
|
6 |
+
# Header and intro
|
7 |
+
st.write("## Introduction to the Knowledge Graph API")
|
8 |
+
st.write("---")
|
9 |
+
st.write("""
|
10 |
+
The Google Knowledge Graph API reveals entity information related to a keyword, that Google knows about.
|
11 |
+
This information can be very useful for SEO – discovering related topics and what Google believes is relevant.
|
12 |
+
It can also help when trying to claim/win a Knowledge Graph box on search results.
|
13 |
+
The API requires a high level of technical understanding, so this tool creates a simple public interface, with the ability to export data into spreadsheets.
|
14 |
+
""")
|
15 |
+
|
16 |
def sample_analyze_entities(text_content):
|
17 |
+
# Parse the JSON string to a dictionary
|
18 |
service_account_info = json.loads(st.secrets["google_nlp"])
|
19 |
+
|
20 |
+
# Create credentials
|
21 |
credentials = service_account.Credentials.from_service_account_info(
|
22 |
service_account_info, scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
23 |
)
|
24 |
+
|
25 |
+
# Initialize the LanguageServiceClient with the credentials
|
26 |
client = language_v1.LanguageServiceClient(credentials=credentials)
|
27 |
|
28 |
+
# NLP analysis
|
29 |
type_ = language_v1.Document.Type.PLAIN_TEXT
|
30 |
language = "en"
|
31 |
document = {"content": text_content, "type_": type_, "language": language}
|
|
|
64 |
st.write(f"**Name**: {entity['Name']}")
|
65 |
st.write(f"**Type**: {entity['Type']}")
|
66 |
st.write(f"**Salience Score**: {entity['Salience Score']}")
|
67 |
+
|
68 |
if entity["Metadata"]:
|
69 |
st.write("**Metadata**: ")
|
70 |
st.json(entity["Metadata"])
|
71 |
+
|
72 |
if entity["Mentions"]:
|
73 |
st.write("**Mentions**: ")
|
74 |
st.json(entity["Mentions"])
|
75 |
|
76 |
|
77 |
+
st.write(f"### Language of the text: {response.language}")
|
|
|
78 |
|
79 |
+
# User input for text analysis
|
80 |
+
user_input = st.text_area("Enter text to analyze")
|
81 |
+
if st.button("Analyze"):
|
82 |
+
sample_analyze_entities(user_input)
|
|