FlaskPower PlatformAIPython

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.

PDF Context Chatbot

๐Ÿ“– 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

LayerTechnology
UIPower Apps (Canvas App)
AutomationPower Automate
BackendPython Flask + Sentence Transformers
Embedding Modelall-mpnet-base-v2
PDF ParsingPyPDF2
HostingNgrok (Dev)
Memory Logspsutil

๐Ÿงญ Architecture Overview

Architecture

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 Apps 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?

  1. Trigger: Captures the question from Power Apps via "When a Power Apps button is clicked".
  2. Step 1: Sends HTTP POST to the Flask API hosted on Ngrok.
  3. Step 2: Receives reduced context (top matching sentences) from PDFs.
  4. Step 3: Sends both context and question into the AI Builder "Run a prompt" action.
  5. Step 4: Returns the AI-generated answer back to Power Apps and updates the UI.
[User Question] โ†’ [Power Automate] โ†’ [Flask API] โ†’ [Reduced Context] โ†’ [AI Prompt] โ†’ [Answer]
Power Automate Flow

๐Ÿงช 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:

"How do I connect Power BI to SharePoint and refresh the data automatically?"

๐Ÿง  Final AI Answer:

To connect Power BI to SharePoint, use the SharePoint Online List connector and provide the site URL and list name. After shaping the data with Power Query, publish the report to Power BI Service. Then, configure automatic refresh under dataset settings โ€” no gateway is needed for SharePoint Online.

๐Ÿ”— 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.

โ† Back to Home