Skip to content

ts-azure-services/cognitive-services-flaskapp

 
 

Repository files navigation

Tutorial: Build a Flask app with Azure Cognitive Services

With this sample, you'll build a Flask web app that uses Azure Cognitive Services to translate text, analyze sentiment, and synthesize translated text into speech. If you run into any issues, let us know by submitting and issue.

What is Flask?

Flask is a microframework for creating web applications. This means Flask provides you with tools, libraries, and technologies that allow you to build a web application. This web application can be some web pages, a blog, a wiki or go as substantive as a web-based calendar application or a commercial website.

For those of you who want to deep dive after this tutorial here are a few helpful links:

Steps

  1. Create a virtual environment called flaskapp, by running conda create -n flaskapp python=3.9.
  2. Activate the virtual environment, by running conda activate flaskapp.
  3. Run make infra at the root directory.

This will use the Makefile to create the translator resource, the speech resource and the text analytics resource, and save the relevant keys to the variables.env file.

  1. Run make setup at the root directory to install the relevant third-party libraries.

This will install the requests library, the python-dotenv library for handling environment variables and the flask library.

  1. Before triggering the following steps, go into the Azure Portal and make sure that Generate Custom Domain Name is clicked under each resource. If resources are created through the CLI, this can be often be a required additional manual step. Once done, give it a few minutes.
  2. To validate the flask install, run flask --version.
  3. Run the flask app by executing the following at the command line:
    1. export FLASK_APP=app.py
    2. export FLASK_DEBUG=1
  4. To run the flask app, execute flask run.
  5. Navigate to the URL provided and test your app.

About

A fork to leverage this repo's demo example.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 33.8%
  • Python 27.0%
  • JavaScript 25.1%
  • Shell 13.7%
  • Makefile 0.4%