AI-Powered PDF Context Chatbot Using Flask & Power Platform
By Sudarshan Awasthi โข 2025
An intelligent chatbot that semantically reads PDFs and answers natural language questions using embeddings, Flask API, and Power Apps UI.

๐ Introduction
In today's information-heavy environments, finding specific content inside large collections of PDFs is frustrating. This project solves that problem by enabling a chatbot to semantically understand and answer user queries โ not just with keyword search, but true contextual understanding.
๐ฏ Problem Statement
Traditional search fails when the exact wording is unknown or information is scattered across documents. This solution enables:
- Natural language question input
- Contextual understanding of PDF content using semantic embeddings
- AI-generated answers
- Seamless low-code UI with Power Platform
๐ ๏ธ Technologies Used
Layer | Technology |
---|---|
UI | Power Apps (Canvas App) |
Automation | Power Automate |
Backend | Python Flask + Sentence Transformers |
Embedding Model | all-mpnet-base-v2 |
PDF Parsing | PyPDF2 |
Hosting | Ngrok (Dev) |
Memory Logs | psutil |
๐งญ Architecture Overview

The architecture consists of five interconnected components:
- Power Apps: Frontend chat UI where the user types a question.
- Power Automate: Middleware that sends the question to the backend and receives the final AI response.
- Flask API: Python server that extracts text from PDFs and uses semantic search to find relevant context.
- AI Builder: Uses the reduced context + question to generate a human-readable answer.
- Power Apps: Displays the AI-generated answer in a user-friendly interface.
This flow enables end-to-end semantic search over PDF documents using natural language โ without requiring the user to browse, scroll, or filter manually.
๐ฌ Power Apps Chat UI

๐ Power Automate โ Orchestrating the Flow
Power Automate plays a crucial role in connecting the user interface built in Power Apps with the backend AI system powered by Flask and Python. It acts as the middleware that sends and receives data, triggers the AI logic, and ensures that user queries are processed intelligently and efficiently.
๐ What Happens in Power Automate?
- Trigger: Captures the question from Power Apps via "When a Power Apps button is clicked".
- Step 1: Sends HTTP POST to the Flask API hosted on Ngrok.
- Step 2: Receives reduced context (top matching sentences) from PDFs.
- Step 3: Sends both context and question into the AI Builder "Run a prompt" action.
- Step 4: Returns the AI-generated answer back to Power Apps and updates the UI.
[User Question] โ [Power Automate Triggered] โ [HTTP โ Flask API] โ [Reduced Context] โ [AI Prompt] โ [Answer Returned]

๐งช Sample Prompt Execution โ Power BI Example
Here's a real-world example that demonstrates how the chatbot processes a Power Platform question using embedded content from Power BI documentation:
๐งพ Question:
๐ Reduced Context:
- Power BI can connect directly to SharePoint Online lists using the SharePoint Online List connector.
- When prompted, users must enter the site URL and then select the list to connect.
- SharePoint data is imported as a structured table that can be shaped using Power Query.
- For scheduled refresh, the dataset must be published to Power BI Service.
- A gateway is not required if the data source is cloud-based, such as SharePoint Online.
- In the Power BI Service, users can configure refresh frequency under the dataset settings.
- You can set up daily or hourly refresh schedules depending on your license tier (Pro or Premium).
- Authentication is typically handled via OAuth2 and requires access permission to the SharePoint site.
- Errors during refresh can be traced in the refresh history panel of the dataset.
- It is important to avoid columns with complex field types like lookup or person fields as they may not load cleanly.
๐ง Final AI Answer:
๐ AI Builder Prompt Format:
Use the following context to answer the user's question. Context: [Top 5โ10 relevant sentences extracted from PDFs] Question: [User input]
๐ Code Repository
Explore the backend Flask code and setup instructions here:
View on GitHubโ Conclusion
This chatbot showcases the power of combining AI, semantic search, and low-code platforms to solve real-world document analysis challenges. It's a production-ready, extensible solution for knowledge retrieval.