dhanishetty commited on
Commit
d2bbaec
·
verified ·
1 Parent(s): 4fc1c7f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from azure.core.credentials import AzureKeyCredential
3
+ from azure.ai.textanalytics import TextAnalyticsClient
4
+
5
+ def EntityRecognition(endpoint, key, statements):
6
+
7
+ if (endpoint == '' or key == ''):
8
+ output = "*** Please provide EndPoint URL and API_KEY ***"
9
+
10
+ else:
11
+ try:
12
+ endpoint = endpoint
13
+ key = key
14
+
15
+ entity_recognition_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
16
+
17
+ documents = tuple(statements.split("\n"))
18
+
19
+ result = entity_recognition_client.recognize_entities(documents)[0]
20
+
21
+
22
+ reviews = ()
23
+ for entity in result.entities:
24
+ reviews = reviews + (f"Text: {entity.text} \t | \t Category: {entity.category} \t | \t Confidence Score: {round(entity.confidence_score, 2)}",)
25
+
26
+ output = "\n".join(reviews)
27
+ except:
28
+ output = "*** Please check EndPoint URL and API_KEY ***"
29
+
30
+ return output
31
+
32
+
33
+
34
+ demo = gr.Interface( fn = EntityRecognition, inputs= [ gr.Textbox("https://t9xt.cognitiveservices.azure.com/",label="Enter your Endpoint URL", placeholder="URL", lines=1), gr.Textbox("46758f0003684f1b8c6fb73dfd7f98db",type = "password", label="Enter your API-Key", placeholder="API-Key", lines=1), gr.Textbox()], outputs= gr.Textbox(), title = title, description = description).launch()