blazingbunny commited on
Commit
2b108c5
·
1 Parent(s): 6258650

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -43,10 +43,44 @@ def sample_analyze_entities(text_content):
43
 
44
  st.write(f"Language of the text: {response.language}")
45
 
46
- # Streamlit UI
47
- st.title('Google Cloud NLP Entity Analyzer')
48
- user_input = st.text_area('Enter text to analyze', '')
49
 
50
- if st.button('Analyze'):
51
- if user_input:
52
- sample_analyze_entities(user_input)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  st.write(f"Language of the text: {response.language}")
45
 
46
+ # Create an empty list to hold the results
47
+ entities_list = []
 
48
 
49
+ for entity in response.entities:
50
+ # Create a dictionary to hold individual entity details
51
+ entity_details = {
52
+ "Name": entity.name,
53
+ "Type": language_v1.Entity.Type(entity.type_).name,
54
+ "Salience Score": entity.salience,
55
+ "Metadata": [],
56
+ "Mentions": []
57
+ }
58
+
59
+ for metadata_name, metadata_value in entity.metadata.items():
60
+ entity_details["Metadata"].append({metadata_name: metadata_value})
61
+
62
+ for mention in entity.mentions:
63
+ entity_details["Mentions"].append({
64
+ "Text": mention.text.content,
65
+ "Type": language_v1.EntityMention.Type(mention.type_).name
66
+ })
67
+
68
+ # Append the dictionary to the list
69
+ entities_list.append(entity_details)
70
+
71
+ # Use Streamlit to display the results
72
+ st.write("### Analyzed Entities")
73
+ for entity in entities_list:
74
+ st.write(f"**Name**: {entity['Name']}")
75
+ st.write(f"**Type**: {entity['Type']}")
76
+ st.write(f"**Salience Score**: {entity['Salience Score']}")
77
+
78
+ if entity["Metadata"]:
79
+ st.write("**Metadata**: ")
80
+ st.json(entity["Metadata"])
81
+
82
+ if entity["Mentions"]:
83
+ st.write("**Mentions**: ")
84
+ st.json(entity["Mentions"])
85
+
86
+ st.write(f"### Language of the text: {response.language}")