prajwal5065/My-Medical-AI-Assistant-Code

The open-source code for my Medical AI Assistant deployed on Hugging Face Spaces

Python

2

5 commits

updated Apr 6, 2026

See the code

README

πŸ₯ MediBot AI β€” My Medical AI Assistant

Python TinyLlama LoRA PEFT Gradio HuggingFace License

A fine-tuned TinyLlama 1.1B medical chatbot trained on a custom medical Q&A dataset using QLoRA β€” deployed live on HuggingFace Spaces with a Gradio UI.

πŸ€— Live Demo Β· ✨ Features Β· πŸ§ͺ Model Details Β· πŸš€ Getting Started


πŸ“Œ Table of Contents


🧠 Overview

MediBot AI is a domain-specific medical chatbot built by fine-tuning TinyLlama-1.1B-Chat on a custom medical_qa.csv dataset using QLoRA (Quantized Low-Rank Adaptation). It answers medical questions covering symptoms, diseases, drug information, general health advice, and more β€” all through a clean Gradio web interface deployed on HuggingFace Spaces.

This project demonstrates a full LLM fine-tuning pipeline: from dataset preparation β†’ QLoRA training β†’ adapter merging β†’ Gradio deployment.


🌐 Live Demo

πŸ€— https://huggingface.co/spaces/Prajwal4107k/My-Medical-AI-Assistant

πŸ’¬ MediBot AI β€” Symptom Query

MediBot Symptoms Demo

Asking "What are the symptoms of diabetes?" β€” MediBot responds with a detailed, numbered breakdown of diabetes symptoms including hyperglycemia, numbness, blurred vision, and fatigue.


🩺 MediBot AI β€” Multi-turn Medical Q&A

MediBot Multi-turn Demo

Multi-turn conversation on HuggingFace Spaces β€” the bot correctly answers "What is the average human temperature?" and provides detailed kidney disease symptom identification when asked.


✨ Features

  • πŸ€– Fine-tuned LLM β€” TinyLlama 1.1B Chat, fine-tuned specifically on medical Q&A data
  • πŸ’Š Medical Q&A β€” Answers questions about symptoms, diseases, and conditions
  • 🌑️ Symptom Checker β€” Identifies possible conditions based on described symptoms
  • πŸ’‰ Drug Information β€” Provides general information about medications
  • 🩺 General Medical Advice β€” Health tips, normal ranges, body metrics
  • πŸ–₯️ Gradio Web UI β€” Clean, dark-themed chat interface with example prompts
  • πŸ€— HuggingFace Spaces β€” Publicly accessible live deployment
  • ⚑ QLoRA Training β€” Efficient fine-tuning with 4-bit quantization using PEFT

πŸ§ͺ Model Details

PropertyValue
Base ModelTinyLlama/TinyLlama-1.1B-Chat-v0.6
Fine-tuning MethodQLoRA (4-bit quantization + LoRA adapters)
LibraryPEFT (Parameter Efficient Fine-Tuning)
Pipelinetext-generation
Training Datamedical_qa.csv (custom Medical Q&A dataset)
Chat TemplateJinja2 (chat_template.jinja)
Adapter FormatSafeTensors (adapter_model.safetensors)
Tagslora, transformers, TinyLlama-adapter

πŸ› οΈ Tech Stack

ComponentTechnology
Base LLMTinyLlama 1.1B Chat
Fine-tuningQLoRA via PEFT + bitsandbytes
Training Scriptfine_tune_qlora.py
FrameworkHuggingFace Transformers
UIGradio
DeploymentHuggingFace Spaces
LanguagePython 3.10+
Data FormatCSV (medical_qa.csv) + JSON (dataset.json)

πŸ“ Project Structure

My-Medical-AI-Assistant-Code/
β”‚
β”œβ”€β”€ fine_tuned_model/                   # Trained LoRA adapter files
β”‚   β”œβ”€β”€ adapter_config.json             # LoRA adapter configuration
β”‚   β”œβ”€β”€ adapter_model.safetensors       # Fine-tuned adapter weights
β”‚   β”œβ”€β”€ chat_template.jinja             # Custom chat prompt template
β”‚   β”œβ”€β”€ special_tokens_map.json         # Special tokens mapping
β”‚   β”œβ”€β”€ tokenizer.json                  # Tokenizer vocabulary
β”‚   β”œβ”€β”€ tokenizer.model                 # SentencePiece tokenizer model
β”‚   β”œβ”€β”€ tokenizer_config.json           # Tokenizer configuration
β”‚   └── README.md                       # Model card
β”‚
β”œβ”€β”€ .gradio/
β”‚   └── certificate.pem                 # Gradio SSL certificate
β”‚
β”œβ”€β”€ app.py                              # Gradio app β€” chat interface
β”œβ”€β”€ fine_tune_qlora.py                  # QLoRA fine-tuning script
β”œβ”€β”€ medical_qa.csv                      # Medical Q&A training dataset
β”œβ”€β”€ dataset.json                        # Processed dataset in JSON format
β”œβ”€β”€ test_imports.py                     # Dependency verification script
β”œβ”€β”€ requirements.txt                    # Python dependencies
└── README.md

βš™οΈ How It Works

medical_qa.csv  β†’  dataset.json
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   fine_tune_qlora.py         β”‚
β”‚                              β”‚
β”‚  β€’ Load TinyLlama-1.1B-Chat  β”‚
β”‚  β€’ 4-bit quantization        β”‚
β”‚  β€’ Attach LoRA adapters      β”‚
β”‚  β€’ Train on medical Q&A      β”‚
β”‚  β€’ Save adapter weights      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
    fine_tuned_model/
    adapter_model.safetensors
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         app.py               β”‚
β”‚                              β”‚
β”‚  β€’ Load base model           β”‚
β”‚  β€’ Merge LoRA adapter        β”‚
β”‚  β€’ Apply chat template       β”‚
β”‚  β€’ Launch Gradio UI          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   MediBot AI        β”‚  ←  User asks medical question
    β”‚   Gradio Chat UI    β”‚  β†’  LLM generates answer
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
    HuggingFace Spaces πŸ€—
    (Public live deployment)

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • GPU recommended (CUDA) for inference; CPU works but is slower
  • HuggingFace account (for model access)

1. Clone the Repository

git clone https://github.com/prajwal5065/My-Medical-AI-Assistant-Code.git
cd My-Medical-AI-Assistant-Code

2. Install Dependencies

pip install -r requirements.txt

Core packages include:

transformers
peft
bitsandbytes
gradio
torch
accelerate
datasets

3. Verify Imports

python test_imports.py

4. (Optional) Re-run Fine-tuning

python fine_tune_qlora.py

⚠️ Requires a CUDA GPU. The script loads medical_qa.csv, applies 4-bit quantization, trains LoRA adapters, and saves them to fine_tuned_model/.


5. Launch the Gradio App

python app.py

The MediBot AI interface will open at http://127.0.0.1:7860


6. Or Use the Live Demo

No setup needed β€” just visit:

πŸ€— https://huggingface.co/spaces/Prajwal4107k/My-Medical-AI-Assistant


⚠️ Disclaimer

MediBot AI is for informational and educational purposes only. It is NOT a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare professional for medical decisions. Never ignore professional medical advice because of something this AI has said.


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built with ❀️ by Prajwal

πŸ€— Try MediBot AI Live on HuggingFace Spaces

⭐ Star this repo if you found it helpful!

prajwal5065/My-Medical-AI-Assistant-Code

The open-source code for my Medical AI Assistant deployed on Hugging Face Spaces

Python

2

5 commits

updated Apr 6, 2026

See the code

README

πŸ₯ MediBot AI β€” My Medical AI Assistant

Python TinyLlama LoRA PEFT Gradio HuggingFace License

A fine-tuned TinyLlama 1.1B medical chatbot trained on a custom medical Q&A dataset using QLoRA β€” deployed live on HuggingFace Spaces with a Gradio UI.

πŸ€— Live Demo Β· ✨ Features Β· πŸ§ͺ Model Details Β· πŸš€ Getting Started


πŸ“Œ Table of Contents


🧠 Overview

MediBot AI is a domain-specific medical chatbot built by fine-tuning TinyLlama-1.1B-Chat on a custom medical_qa.csv dataset using QLoRA (Quantized Low-Rank Adaptation). It answers medical questions covering symptoms, diseases, drug information, general health advice, and more β€” all through a clean Gradio web interface deployed on HuggingFace Spaces.

This project demonstrates a full LLM fine-tuning pipeline: from dataset preparation β†’ QLoRA training β†’ adapter merging β†’ Gradio deployment.


🌐 Live Demo

πŸ€— https://huggingface.co/spaces/Prajwal4107k/My-Medical-AI-Assistant

πŸ’¬ MediBot AI β€” Symptom Query

MediBot Symptoms Demo

Asking "What are the symptoms of diabetes?" β€” MediBot responds with a detailed, numbered breakdown of diabetes symptoms including hyperglycemia, numbness, blurred vision, and fatigue.


🩺 MediBot AI β€” Multi-turn Medical Q&A

MediBot Multi-turn Demo

Multi-turn conversation on HuggingFace Spaces β€” the bot correctly answers "What is the average human temperature?" and provides detailed kidney disease symptom identification when asked.


✨ Features

  • πŸ€– Fine-tuned LLM β€” TinyLlama 1.1B Chat, fine-tuned specifically on medical Q&A data
  • πŸ’Š Medical Q&A β€” Answers questions about symptoms, diseases, and conditions
  • 🌑️ Symptom Checker β€” Identifies possible conditions based on described symptoms
  • πŸ’‰ Drug Information β€” Provides general information about medications
  • 🩺 General Medical Advice β€” Health tips, normal ranges, body metrics
  • πŸ–₯️ Gradio Web UI β€” Clean, dark-themed chat interface with example prompts
  • πŸ€— HuggingFace Spaces β€” Publicly accessible live deployment
  • ⚑ QLoRA Training β€” Efficient fine-tuning with 4-bit quantization using PEFT

πŸ§ͺ Model Details

PropertyValue
Base ModelTinyLlama/TinyLlama-1.1B-Chat-v0.6
Fine-tuning MethodQLoRA (4-bit quantization + LoRA adapters)
LibraryPEFT (Parameter Efficient Fine-Tuning)
Pipelinetext-generation
Training Datamedical_qa.csv (custom Medical Q&A dataset)
Chat TemplateJinja2 (chat_template.jinja)
Adapter FormatSafeTensors (adapter_model.safetensors)
Tagslora, transformers, TinyLlama-adapter

πŸ› οΈ Tech Stack

ComponentTechnology
Base LLMTinyLlama 1.1B Chat
Fine-tuningQLoRA via PEFT + bitsandbytes
Training Scriptfine_tune_qlora.py
FrameworkHuggingFace Transformers
UIGradio
DeploymentHuggingFace Spaces
LanguagePython 3.10+
Data FormatCSV (medical_qa.csv) + JSON (dataset.json)

πŸ“ Project Structure

My-Medical-AI-Assistant-Code/
β”‚
β”œβ”€β”€ fine_tuned_model/                   # Trained LoRA adapter files
β”‚   β”œβ”€β”€ adapter_config.json             # LoRA adapter configuration
β”‚   β”œβ”€β”€ adapter_model.safetensors       # Fine-tuned adapter weights
β”‚   β”œβ”€β”€ chat_template.jinja             # Custom chat prompt template
β”‚   β”œβ”€β”€ special_tokens_map.json         # Special tokens mapping
β”‚   β”œβ”€β”€ tokenizer.json                  # Tokenizer vocabulary
β”‚   β”œβ”€β”€ tokenizer.model                 # SentencePiece tokenizer model
β”‚   β”œβ”€β”€ tokenizer_config.json           # Tokenizer configuration
β”‚   └── README.md                       # Model card
β”‚
β”œβ”€β”€ .gradio/
β”‚   └── certificate.pem                 # Gradio SSL certificate
β”‚
β”œβ”€β”€ app.py                              # Gradio app β€” chat interface
β”œβ”€β”€ fine_tune_qlora.py                  # QLoRA fine-tuning script
β”œβ”€β”€ medical_qa.csv                      # Medical Q&A training dataset
β”œβ”€β”€ dataset.json                        # Processed dataset in JSON format
β”œβ”€β”€ test_imports.py                     # Dependency verification script
β”œβ”€β”€ requirements.txt                    # Python dependencies
└── README.md

βš™οΈ How It Works

medical_qa.csv  β†’  dataset.json
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   fine_tune_qlora.py         β”‚
β”‚                              β”‚
β”‚  β€’ Load TinyLlama-1.1B-Chat  β”‚
β”‚  β€’ 4-bit quantization        β”‚
β”‚  β€’ Attach LoRA adapters      β”‚
β”‚  β€’ Train on medical Q&A      β”‚
β”‚  β€’ Save adapter weights      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
    fine_tuned_model/
    adapter_model.safetensors
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         app.py               β”‚
β”‚                              β”‚
β”‚  β€’ Load base model           β”‚
β”‚  β€’ Merge LoRA adapter        β”‚
β”‚  β€’ Apply chat template       β”‚
β”‚  β€’ Launch Gradio UI          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   MediBot AI        β”‚  ←  User asks medical question
    β”‚   Gradio Chat UI    β”‚  β†’  LLM generates answer
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
    HuggingFace Spaces πŸ€—
    (Public live deployment)

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • GPU recommended (CUDA) for inference; CPU works but is slower
  • HuggingFace account (for model access)

1. Clone the Repository

git clone https://github.com/prajwal5065/My-Medical-AI-Assistant-Code.git
cd My-Medical-AI-Assistant-Code

2. Install Dependencies

pip install -r requirements.txt

Core packages include:

transformers
peft
bitsandbytes
gradio
torch
accelerate
datasets

3. Verify Imports

python test_imports.py

4. (Optional) Re-run Fine-tuning

python fine_tune_qlora.py

⚠️ Requires a CUDA GPU. The script loads medical_qa.csv, applies 4-bit quantization, trains LoRA adapters, and saves them to fine_tuned_model/.


5. Launch the Gradio App

python app.py

The MediBot AI interface will open at http://127.0.0.1:7860


6. Or Use the Live Demo

No setup needed β€” just visit:

πŸ€— https://huggingface.co/spaces/Prajwal4107k/My-Medical-AI-Assistant


⚠️ Disclaimer

MediBot AI is for informational and educational purposes only. It is NOT a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare professional for medical decisions. Never ignore professional medical advice because of something this AI has said.


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built with ❀️ by Prajwal

πŸ€— Try MediBot AI Live on HuggingFace Spaces

⭐ Star this repo if you found it helpful!