0% found this document useful (0 votes)
5 views9 pages

Flask Publish

Flask Publish ML APP

Uploaded by

saqib javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

Flask Publish

Flask Publish ML APP

Uploaded by

saqib javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Publish Flask Api

Create Virtual Environment


First you need to create virtual environment to by using the command
python -m venv env

This command create a folder in your project directory

Activate virtual environment

go to your_ptoject/env/scripts at this path you will get an exe name activate run this in cmd

Install Libraries
install required libruaries by using pip command as below

Pip install flask

Pip install tqdm

Pip install supervision

Pip install torch

Pip install requests

Pip install pandas

pip install wfastcgi

update web.config file:

change handler path to your project

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

<system.webServer>

<handlers>

<add name="Python FastCGI" path="*" verb="*"


modules="FastCgiModule" scriptProcessor="<Path_to_your_project>\env\Scripts\python.exe|<Path_to_your_p
roject>\env\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" />

<add name="PythonAPI" path="*" verb="*" modules="FastCgiModule"


resourceType="Unspecified" requireAccess="Script" />

</handlers>

<httpErrors errorMode="Detailed"/>

<asp scriptErrorSentToBrowser="true"/>

<security>

<requestFiltering>

<verbs>

<clear /> <!-- Clear all existing handlers -->

<add verb="GET" allowed="true" />

<add verb="POST" allowed="true" />

</verbs>

</requestFiltering>

</security>

</system.webServer>

</configuration>
Installing IIS feature with CGI role
The Flask application connects with the FastCGI module of the server to expose the micro-service APIs. So, we have
to install the IIS feature in the Windows server and enable the CGI role. The following steps will help to do it:

Open Server Manager and select Manage > Add Roles and Features.

Click “Next” and select “Role-based or feature-based installation” and select “Next”

Accept the default configurations and continue till we see the “Role Services” screen. Select “CGI” under
“Application Development” and select “Next”
Accept the default configurations and select “Install”.

Enable wfastcgi

Go to this path “<Your_Project>\env\Scripts\” and execute the “wfastcgi-enable.exe” file. This


will enable the FastCGI module and attach it with the IIS server.

This should create an entry for FastCGI pointing to the wfastcgi module in IIS Server. Verify the entry under FastCGI
Settings in IIS Manager root server.
To host the Flask Application, we need to create a website using IIS Manager that can serve our application. Open
IIS Manager > Sites > Default Web Site (Default Web Site must display the FlaskApp folder).

Now, verify the module mapping in FastCGI Settings in the root server. This should create an entry in FastCGI
Settings.

Update the FastCGI Application


Double click the application entry in FastCGI settings to edit the application and select “Environment Variables”.
Click on “…” and open the “EnvironmentVariables Collection Editor”.

Add the below entries:

Name: PYTHONPATH
Value: <Path_to_your_project>
The PYTHONPATH must point to the directory containing the Flask Application.

Name: WSGI_HANDLER
Value: main.app

go to application pool advance setting and set identity to localhost

You might also like