AzureAIServices / app.py
wookimchye's picture
Upload app.py
39f327f verified
raw
history blame contribute delete
874 Bytes
#!/usr/bin/env python
# coding: utf-8
# In[5]:
import gradio as gr
from dotenv import load_dotenv
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
global ai_endpoint
global ai_key
load_dotenv()
ai_endpoint = os.getenv('AI_SERVICE_ENDPOINT')
ai_key = os.getenv('AI_SERVICE_KEY')
def GetLanguage(text):
# Create client using endpoint and key
credential = AzureKeyCredential(ai_key)
client = TextAnalyticsClient(endpoint=ai_endpoint, credential=credential)
# Call the service to get the detected language
detectedLanguage = client.detect_language(documents = [text])[0]
return detectedLanguage.primary_language.name
def greet(name):
return "Language: " + name
demo = gr.Interface(fn=GetLanguage, inputs="text", outputs="text")
demo.launch(share=True)
# In[ ]: