GithubHelp home page GithubHelp logo

azure-samples / function-python-ai-textsummarize Goto Github PK

View Code? Open in Web Editor NEW
15.0 14.0 12.0 61 KB

This sample shows how to take text documents as a input via BlobTrigger, does Text Summarization processing using the AI Congnitive Language service, and then outputs to another text document using BlobOutput binding. Uses Azure Functions Python v2 programming model.

License: MIT License

Dockerfile 0.59% Bicep 97.37% Python 2.04%
azd-templates azure azure-function cognitive-services azd

function-python-ai-textsummarize's Introduction

page_type languages products urlFragment name description
sample
azdeveloper
python
bicep
azure
azure-functions
ai-services
azure-cognitive-search
function-python-ai-textsummarize
Azure Functions - Text Summarization using AI Cognitive Language Service (Python v2 Function)
Take text documents as a input via BlobTrigger with Python, does Text Summarization processing using the AI Congnitive Language service, and then outputs to another text document using BlobOutput binding.

Azure Functions

Text Summarization using AI Cognitive Language Service (Python v2 Function)

This sample shows how to take text documents as a input via BlobTrigger, does Text Summarization processing using the AI Congnitive Language service, and then outputs to another text document using BlobOutput binding.

Open in GitHub Codespaces

Run on your local environment

Pre-reqs

  1. Python 3.78 - 3.11 required
  2. Azure Functions Core Tools
  3. Azurite

The easiest way to install Azurite is using a Docker container or the support built into Visual Studio:

docker run -d -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite
  1. Once you have your Azure subscription, create a Language resource in the Azure portal to get your key and endpoint. After it deploys, click Go to resource. You will need the key and endpoint from the resource you create to connect your application to the API. You'll need to store the key and endpoint into the Env Vars or User Secrets code in a next step the quickstart. You can use the free pricing tier (Free F0) to try the service, and upgrade later to a paid tier for production.
  2. Export these secrets as Env Vars using values from Step 4.

Mac/Linux

export AI_URL=*Paste from step 4*
export AI_SECRET=*Paste from step 4*

Windows

Search for Environment Variables in Settings, create new System Variables similarly to these instructions:

Variable Value
AI_URL Paste from step 4
AI_SECRET Paste from step 4
  1. Azure Storage Explorer or storage explorer features of Azure Portal
  2. Add this local.settings.json file to the text_summarize folder to simplify local development. Optionally fill in the AI_URL and AI_SECRET values per step 4. This file will be gitignored to protect secrets from committing to your repo.
{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "blobstorage": "UseDevelopmentStorage=true",
    "AI_URL": "",
    "AI_SECRET": ""
  }
}

Using VS Code

  1. Open the ./text_summarize folder in VS Code:
cd ./text_summarize
code .
  1. When prompted in VS Code, Create Virtual Environment and choose your version of Python if prompted.
  2. Run and Debug by pressing F5
  3. Open Storage Explorer, Storage Accounts -> Emulator -> Blob Containers -> and create a container test-samples-trigger if it does not already exists
  4. Copy any .txt document file with text into the test-samples-trigger container

You will see AI analysis happen in the Terminal standard out. The analysis will be saved in a .txt file in the test-samples-output blob container.

Using Functions CLI

  1. Open a new terminal and do the following:
cd text_summarize
pip3 install -r requirements.txt
func start
  1. Open Storage Explorer, Storage Accounts -> Emulator -> Blob Containers -> and create a container test-samples-trigger if it does not already exists
  2. Copy any .txt document file with text into the test-samples-trigger container

You will see AI analysis happen in the Terminal standard out. The analysis will be saved in a .txt file in the test-samples-output blob container.

Deploy to Azure

The easiest way to deploy this app is using the Azure Developer CLI. If you open this repo in GitHub CodeSpaces the AZD tooling is already preinstalled.

To provision and deploy:

azd up

function-python-ai-textsummarize's People

Contributors

jianingwang123 avatar microsoft-github-operations[bot] avatar microsoftopensource avatar paulyuk avatar v-xuto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

function-python-ai-textsummarize's Issues

Run and Debug fail in VS Code

Describe the issue:
When using VS Code, Run and Debug according to README.md, the error is as follows:

image

Repro Steps:

  1. Clone the code to local and open the root folder in VS Code.
  2. Run and Debug by pressing F5

Environment:

  • OS: Windows desktop.

Expected behavior:
Run and Debug can pass.

@hemarina for notification.

Summarizer not working

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Clone the repo and do the steps indicated in the READ.ME

Any log messages given by the failure

I deployed the app to azure and when I use F5 to run it i get this pop-up error:
image
And in the output I get this error:
image
I also get this warning in the launch.json:
image
I manually created the test-samples-trigger container and loaded it with a text file to summarize but it didn't do anything, I also tried to create the test-samples-output manually but the app did not generate any summary. The other two azure-webjobs containers were created automatically by the app I think:
image
Here is the full output that I got after running the app:
Output.txt

Expected/desired behavior

App to summarize the .txt files I feed it

OS and Version?

Windows 10

Versions

Python 3.10

Mention any other details that might be useful

I already tried to reinstall azure-core azure-ai-textanalytics but it didn't help
Thank you in advance for your help :)


Thanks! We'll be in touch soon.

Recommend updating appservice.bicep to latest azure-dev files

In the original version of appservice.bicep, appSettings was not wrapped with an @secure decorator, so if a developer put any secrets in their app settings, it would leak into deployment outputs and cause a security alert. The latest version now has the secure decorator.

I noticed this repo is using the old version, so I recommend upgrading if you can.

You can git clone https://github.com/azure/azure-dev and then cp like this:

cp ../azure-dev/templates/common/infra/bicep/core/host/* infra/core/host/.

Or only cp app service files if you don't use other hosts:

cp ../azure-dev/templates/common/infra/bicep/core/host/appservice* infra/core/host/.

Then run azd up to make sure all still works.

Updating/work-with this template for Azd Devcontainer feature.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

We are updating this template to support new features in Azd Devcontainer.

For the Azd Devcontainer feature: We will add the following code in devcontainer.json file.

"ghcr.io/azure/azure-dev/azd:latest": {}

And remove the relevant code for installing azd in Dockerfile under .devcontainer folder.

RUN curl -fsSL https://aka.ms/install-azd.sh | bash \

@rajeshkamal5050 , @paulyuk for notification.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.