Many websites that provide a public service have that little box in the bottom right of the screen. It might be labelled Help, Chat to an Advisor, or something else, but it almost always opens a small window where you can enter specific queries and get AI-powered answers.
If you’ve ever wondered how this works and how to implement it, this article is for you: I show you how to create a test website, add a chatbot to it, and test it locally before deploying it to the public internet. We’ll provide a PDF knowledge base with the kind of information users normally ask about (e.g., business hours, services we provide, etc.). The application searches the PDF, passes the closest passages to a small language model, and displays the answer.
That being said, treat this app as a proof of concept (POC). You can build on it if you need to deliver a more robust and resilient system. This implementation demonstrates the workflow, but it doesn’t have the reliability needed or the AI power for unattended customer support. The language model used can invent facts or follow instructions that take it outside the intended business topic.
Note: the fullthe following link:
Understanding what runs where
Whilst a website and Python code are hosted on your PC, your PC powers the models. Once deployed, Hugging Face hosts the Python code, meaning that anyone can use your website. A user interacts with the websiteto activate the chat function. The user’s question is then passed to the Python code using Gradio. Gradio also supplies the web interface and controls the request queue. Diagrammatically, it looks like this

When a visitor submits a question, the website uses the Gradio JavaScript client (inside the index.html file) to call the application’s named /answer endpoint. Gradio queues the request, and the Python application searches the PDF for relevant passages. If no passages meet the similarity threshold, it returns a fixed message explaining that it couldn’t find the information. Otherwise, it passes the retrieved passages and the question to the language model.
Gradio provides the framework and server-side queue. The system then extracts text from a PDF using pypdf. The program then breaks it into overlapping sections. The program encodes both the text and query sections into vector form using the all-MiniLM-L6-v2 embedding model. NumPy then compares these vectors to locate suitable text. Finally, Qwen2.5–0.5B-Instruct produces an answer based on this text. Both of these models are available under the Apache 2.0 licence. Although the compact Qwen model has low resource needs, further evaluation is required to assess the quality and speed of its answers relative to the specific source material. This approach is called retrieval-augmented generation (RAG). It supplies the language model with reference passages when answering a question, without retraining the model on the PDF.
A dedicated vector database isn’t required for the simple PDF we’ll be using. On initialisation, text is scraped from the PDF and segmented. These segments are then converted to embeddings and placed within a NumPy array. If required, model files are automatically downloaded and existing cached versions are used where possible. Because the PDF is in the Space storage system, it’s possible to re-index it each time the application initialises in a new environment.
Prerequisites
There are a couple of things you need to set up.
-
A PDF business information document.
Use a short, readable PDF containing only information intended for public visitors. Make sure prices, policies, opening hours, etc. are up to date. For an initial test, we’ll use a plain-text page rather than a brochure dominated by diagrams and complex tables.
The included business.pdf describes the fictional Cedar Workshop: furniture repairs and restoration in Glasgow, Monday to Friday from 09:00 to 17:00, closed at weekends. Its contact email uses the reserved .example domain to emphasise that this is invented test data. In our HF setup, this file is public, so make sure you don’t include any confidential information in your own HF setup.
-
A Hugging Face account.
This is free to set up. Head over to https://huggingface.co/ , click the Sign Up button and follow the on-screen instructions
Note: HF currently says free personal accounts must have a verified email, be older than 30 days and be in good standing to host up to two ZeroGPU Spaces and usage is subject to quotas and queues
Create the project structure and files
I’ll build and run this from a Windows PC, but it should be roughly the same setup regardless of your compute environment.
Start by creating a folder structure that looks like this.
business-chatbot/README.mdrequirements.txtrag.pyapp.pybusiness.pdfstatic/index.html
Don’t worry about the individual files for now. We’ll go over those now, and you can always download the entire set of files from my GitHub repo.
Understanding the project files
README.md
The README file includes information on the application’s functionality and how to host it on Hugging Face or on your own machine. It also includes a section that tells Hugging Face which interface (Gradio) to use, along with the framework version and the main application file (app.py).
requirements.txt
Outlines the Python dependencies for the application; these include Gradio, PyTorch, Transformers, and a PDF reader. Apart from the‘spaces’ package, most dependencies have specific version numbers to keep versions consistent. This means that Hugging Face can then host the application using its own suitable version of the spaces library.
app.py
Starts the application, serves the website and connects visitor questions to the chatbot. It validates questions, manages the Gradio request queue and requests ZeroGPU processing when the language model needs to generate an answer.
rag.py
Contains the document-search and answer-generation logic. It extracts text from the PDF, divides it into passages, creates searchable embeddings and retrieves relevant passages for each question. It then supplies those passages to the language model and returns its answer with the retrieved
business.pdf
Provides the chatbot’s reference information. The included document describes the fictional Cedar Workshop; replace it with a readable PDF containing your own public business information.
static/index.html
Defines the visible website, including its styling, business information and the “Ask a question” button. Its JavaScript opens the chat panel, submits questions through the Gradio client and displays answers, retrieved passages and error messages. The test website you see in this article is fictitious and was written by AI.
From a question to an answer
The answer() function in app.py connects document retrieval to answer generation:
def answer(question):question = question.strip()if not question or len(question) > 1000:raise gr.Error("Please enter a question of 1–1000 characters.")sources = engine.retrieve(question)if not sources:return {"answer": UNKNOWN, "sources": []}return generate(question, sources)
After validating the question, engine.retrieve() converts it into an embedding and compares it with the PDF’s passage embeddings. It returns up to three passages whose similarity scores meet the MIN_SCORE threshold.
If no passages qualify, the application returns a fixed response without calling the language model:
I couldn’t find that information in the business guide. Please contact the business to confirm.
Otherwise, generate() passes the question and retrieved passages to the model. On Hugging Face, this function requests GPU time through ZeroGPU.
This check prevents generation when retrieval finds no suitable match. It doesn’t guarantee that a retrieved passage contains the answer: related text can still lack the requested information, and the model may invent a response.
Local development and testing
-
Install Python 3.11. Within the business-chatbot folder (which contains the app.py file), open PowerShell. Then create a Python virtual environment and install the required packages.
py -3.11 -m venv .venv..venvScriptspython.exe -m pip install -r requirements.txt
Define these environment variables prior to running the programme.
$env:MODEL_DEVICE = "cpu"$env:MIN_SCORE = "0.10"..venvScriptspython.exe app.py
While 0.10 is used as the default similarity threshold in this example, increasing it will reduce the amount of matching text, and a smaller value may allow less relevant text to be accepted.
Access the URL http://localhost:7860. This should display something like:

Clicking the Ask a question button at the bottom right should pop up a small window like this that you enter queries into and get answers.

If any existing programs already use port 7860, stop them before starting the website. To stop the website after it’s running, press Ctrl+C in the same command line window you started it.
Running and testing the website on Hugging Face
When you’re happy that everything works as it should locally, we can deploy our website to Hugging Face by following these steps.
Step 1: Log in to your HF account.
Step 2: Click the Spaces link near the top, then click the +New Space button.
Step 3: Fill in the fields like this.
-
Short Description: website-chatbox-test
Step 4: Click the Create Space button.
Step 5: Go to your new Space page and click the Files link near the top. Now upload only the six application files shown in the project tree in your local folder that make up the website into the Files section. Do that by clicking the+Contribute button and selecting theUpload filesoption.
Step 6: When your file upload is finished, HF should automatically build your application and display the website when finished. Make sure it works the same way as it did when you ran it locally. Leave MODEL_DEVICE unset on Hugging Face so the application uses ZeroGPU. The MODEL_DEVICE="cpu" setting is only for running it locally.
If you want to try out my example website, it’s available at
Model constraints
Qwen2.5–0.5B-Instruct is a small model (~0.5 billion parameters). Although our example serves well as a ‘proof of concept’, the underlying AI model it uses can’t always fully comprehend information and apply instructions. It may also add redundant information and/or fail to recognise constraints. Fabricated information can also be provided. Larger models are susceptible to similar issues, and so there are multiple aspects to consider when assessing models — including their capability, the document quality, and how information is retrieved and prompted.
For this example, a positive similarity score cut-off value of 0.10 has been selected. Increasing this will result in fewer sections being returned for search. Conversely, lowering it could include irrelevant information.
Additional assessment and improved evidence validation could be implemented within a live system. This might involve employing a more powerful model, checking that the retrieved passages support the claims made in the generated answer or having the system provide extractive outputs (returning. Here, though, the original small model and retrieval and generation process have both been maintained
Summary
This article describes the development of a website which includes a chatbot able to provide information based on business-specific data inside a PDF. MiniLM produces vector embeddings from both the PDF and user query. NumPy analyses these to identify relevant PDF sections, which are then used by Qwen to form a reply. This is known as Retrieval Augmented Generation – providing a model with information to base replies on without retraining it.
Python and Gradio were used to develop and test the app and it was then published on Hugging Face Spaces using ZeroGPU. Eligible personal accounts can host this prototype using ZeroGPU, subject to usage quotas and shared GPU availability. Again, this is free to do; however, usage will be affected by both Hugging Face’s own limits and by the availability of shared GPUs.
Whilst this illustrates how information can be retrieved from a PDF to enable a reply, it also highlights the shortcomings of a compact language model. Information may be successfully located, but this doesn’t always translate into an accurate answer.
For a production system, further work would be required to evaluate and refine response accuracy, alongside mechanisms to ensure replies are appropriately backed up by information in the referenced document. Additional functionality would also need to be incorporated to ensure that this is fit for purpose as a publicly available service.
