You are not allowed to view this page.
Approved 2025/12/12 16:47 by ddehamer (version: 1) | Approver: @ai-us-principals
Product Sentiment Analysis App
This is a web application that searches X/Twitter for tweets about a product, analyzes their sentiment using Azure Cognitive Services and Azure OpenAI, and displays a summary.
Infrastructure
Required Services
Environment Variables
`AZURE_OPENAI_KEY`
`AZURE_OPENAI_ENDPOINT`
`AZURE_OPENAI_DEPLOYMENT_NAME`
`AZURE_TEXT_ANALYTICS_KEY`
`AZURE_TEXT_ANALYTICS_ENDPOINT`
`X_BEARER_TOKEN`
Store them in a `.env` file or as App Settings in Azure App Service.
Backend Code (app.py)
Libraries Used
`fastapi` – Defines HTTP endpoints.
`requests` – Used to interact with the Twitter
API.
`openai` – Azure OpenAI SDK for calling GPT models.
`azure.ai.textanalytics` – Azure SDK for Text Analytics
API.
`jinja2` – Template rendering.
`uvicorn` – Development server for FastAPI.
Endpoints
Key Functions
-
-
Auth: Bearer Token (`X_BEARER_TOKEN`)
Returns up to 10 recent English tweets about the keyword.
analyze_sentiment(texts)
Calls Azure Text Analytics
API:
Endpoint: `<AZURE_TEXT_ANALYTICS_ENDPOINT>/text/analytics/v3.1/sentiment`
Auth:
API Key (`AZURE_TEXT_ANALYTICS_KEY`)
Returns document sentiment (positive, negative, neutral) and confidence scores.
Calls Azure OpenAI Chat Completions
API:
Endpoint: `<AZURE_OPENAI_ENDPOINT>/openai/deployments/<DEPLOYMENT_NAME>/chat/completions`
Model: gpt-35-turbo or compatible
Prompts GPT to summarize public sentiment based on labeled tweet data.
Frontend Code (index.html)
Uses Bootstrap for styling. Features:
User Steps
2. Install Dependencies
Run:
pip install -r requirements.txt
3. Launch the App
Run:
uvicorn app:app --reload
Then open your browser to:
http://localhost:8000
4. Use the App
Enter a product keyword (e.g., “AirPods”).
Submit.
View tweet list with sentiment tags.
View summary generated by GPT.
File Structure
| File | Purpose |
| `app.py` | Main backend logic |
| `templates/index.html` | Frontend |
| `requirements.txt` | Dependencies |
How It Works
User inputs a keyword.
Tweets are fetched using Twitter
API v2.
Sentiment analysis is performed using Azure Text Analytics.
Tweets are summarized using Azure OpenAI GPT.
Result is rendered via
HTML template.