Spaces:
Sleeping
Sleeping
File size: 1,726 Bytes
32bfec1 1ac0df3 4719fd1 99b99dc b596da1 1ac0df3 b596da1 1ac0df3 09032ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import gradio as gr
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
def AnalyzeSentiment(endpoint, key, statements):
if (endpoint == '' or key == ''):
output = "*** Please provide EndPoint URL and API_KEY ***"
else:
try:
endpoint = endpoint
key = key
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
documents = tuple(statements.split("\n"))
result = text_analytics_client.analyze_sentiment(documents, show_opinion_mining=True)
docs = [doc for doc in result if not doc.is_error]
reviews = ()
for idx, doc in enumerate(docs):
reviews = reviews + (f"Document text: {documents[idx]}",)
reviews = reviews + (f"Overall sentiment: {doc.sentiment} {doc.confidence_scores}",)
output = "\n\n".join(reviews)
except:
output = "*** Please check EndPoint URL and API_KEY ***"
return output
title = "Azure Cognitive Services"
description = """
<img src = "https://nightingalehq.ai/knowledgebase/glossary/what-are-azure-cognitive-services/cognitive-services.jpg" width = 300px>
# Language Service : Use Natural Language Understanding (NLU) for Sentiment analysis and opinion mining.
"""
demo = gr.Interface( fn = AnalyzeSentiment, inputs= [ gr.Textbox(label="Enter your Endpoint URL", placeholder="URL", lines=1), gr.Textbox(type = "password", label="Enter your API-Key", placeholder="API-Key", lines=1), gr.Textbox()], outputs= gr.Textbox(), title = title, description = description).launch() |