this is the "app.py" file in the Github repository.
from flask import Flask, jsonify, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
# LUIS_Intent
from azure.cognitiveservices.language.luis.runtime import LUISRuntimeClient
from msrest.authentication import CognitiveServicesCredentials
import json
# Entity
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
class Intent_EU_Taxo(Resource):
def get(self, sentence):
predictionKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
predictionEndpoint = 'https://XXXXXXXXXXXX.cognitiveservices.azure.com/'
app_id = 'XXXXXXXXXXXXXXXXXX'
runtimeCredentials = CognitiveServicesCredentials(predictionKey)
clientRuntime = LUISRuntimeClient(endpoint=predictionEndpoint, credentials=runtimeCredentials)
predictionRequest = { "query" : sentence}
predictionResponse = clientRuntime.prediction.get_slot_prediction(app_id, "Production", predictionRequest)
top_intent_score = predictionResponse.prediction.intents[predictionResponse.prediction.top_intent].score
return jsonify({'type': predictionResponse.prediction.top_intent, 'score': top_intent_score})
class Orga_Entity(Resource):
def get(self, sentence):
credential = AzureKeyCredential("XXXXXXXXXXXXXXXXXXXX")
text_analytics_client = TextAnalyticsClient(endpoint="https://XXXXXXXXXXXXXXXX.cognitiveservices.azure.com/", credential=credential)
documents = [sentence]
response = text_analytics_client.recognize_entities(documents, language="de")
result = [doc for doc in response if not doc.is_error]
entity_list = []
for doc in result:
for entity in doc.entities:
if entity.category == "Organization" and entity.confidence_score >= 0.5:
entity_list.append(entity.text)
else:
pass
return jsonify({'Company': entity_list[0]})
api.add_resource(Intent_EU_Taxo, '/intent/<sentence>')
api.add_resource(Orga_Entity, '/entity/<sentence>')
if __name__ == '__main__':
app.run()
This is how my github folder looks like.
This is in the requirements.txt file in the github repository:
Flask==1.1.2
Flask-restful==0.3.9
azure-ai-textanalytics==5.1.0
azure-cognitiveservices-language-luis==0.7.0
msrest==0.7.1
azure-core==1.24.2
azure-ai-textanalytics==5.1.0
I deploy this github repository to the azure app service with python 3.9 runtime. The deployment looks fine.
deploy from github on azure app
However, when I test it like "http://XXXXXXXX.azurewebsites.net/entity/"EU Taxo check für Siemens", it does not return the json result which I get in the local deployment.
Local deployment: local deployment
Deployment on Azure: enter image description here
I google a lot, but doesn't know what's wrong with my deployment.... I am very new to flask app and azure app service, please forgive me if it looks stupid. Thanks for every tips!