Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- .env +1 -0
- .gitattributes +6 -0
- .gitignore +54 -0
- README.md +131 -3
- app.py +176 -0
- medisync-ai.ipynb +1135 -0
- requirements.txt +73 -0
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GOOGLE_API_KEY = AIzaSyBy75oZVqdS-2AUwS0TMH8aiIGF64GbTL8
|
.gitattributes
CHANGED
|
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
|
| 38 |
+
.venv/* linguist-vendored
|
| 39 |
+
.venv/** linguist-vendored
|
| 40 |
+
gradio-env/** linguist-vendored
|
| 41 |
+
.gradio/** linguist-vendored
|
.gitignore
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*.pyo
|
| 5 |
+
*.so
|
| 6 |
+
*.log
|
| 7 |
+
|
| 8 |
+
# Virtual Environments
|
| 9 |
+
.venv/
|
| 10 |
+
venv/
|
| 11 |
+
env/
|
| 12 |
+
ENV/
|
| 13 |
+
gradio-env/
|
| 14 |
+
|
| 15 |
+
# Gradio
|
| 16 |
+
.gradio/
|
| 17 |
+
gradio/
|
| 18 |
+
|
| 19 |
+
# Jupyter
|
| 20 |
+
.ipynb_checkpoints/
|
| 21 |
+
|
| 22 |
+
# VS Code
|
| 23 |
+
.vscode/
|
| 24 |
+
|
| 25 |
+
# System
|
| 26 |
+
.DS_Store
|
| 27 |
+
Thumbs.db
|
| 28 |
+
|
| 29 |
+
# Hugging Face and Gradio
|
| 30 |
+
*.huggingface
|
| 31 |
+
*.gradio
|
| 32 |
+
token
|
| 33 |
+
|
| 34 |
+
# Model/Data files
|
| 35 |
+
*.ckpt
|
| 36 |
+
*.pt
|
| 37 |
+
*.pth
|
| 38 |
+
*.h5
|
| 39 |
+
*.tflite
|
| 40 |
+
*.pb
|
| 41 |
+
*.onnx
|
| 42 |
+
*.joblib
|
| 43 |
+
*.pkl
|
| 44 |
+
*.pickle
|
| 45 |
+
*.npy
|
| 46 |
+
*.npz
|
| 47 |
+
*.tar
|
| 48 |
+
*.tar.gz
|
| 49 |
+
*.zip
|
| 50 |
+
*.gz
|
| 51 |
+
*.rar
|
| 52 |
+
|
| 53 |
+
# LFS-tracked artifacts
|
| 54 |
+
*.lfs.*
|
README.md
CHANGED
|
@@ -1,12 +1,140 @@
|
|
| 1 |
---
|
| 2 |
title: MediSyncAI
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.25.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
|
|
|
|
|
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: MediSyncAI
|
| 3 |
+
emoji: 🏆
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.25.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: An AI-Powered Medical Assistant for Rural Clinics
|
| 12 |
---
|
| 13 |
|
| 14 |
+
<!-- @format -->
|
| 15 |
+
|
| 16 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 17 |
+
|
| 18 |
+
# 🏥 MediSync.AI – An AI-Powered Medical Assistant for Rural Clinics
|
| 19 |
+
|
| 20 |
+
MediSync.AI is a GenAI-powered web application designed to **assist rural healthcare centers** by automatically understanding **prescriptions** and providing **interactive medical insights** through a conversational agent. Built using **Google Gemini 2.0 Flash API via Vertex AI**, this tool simplifies medical communication for patients and supports doctors with AI-enhanced assistance.
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## 📌 Features
|
| 25 |
+
|
| 26 |
+
- 🧠 **Prescription Understanding**
|
| 27 |
+
Upload an image of a handwritten prescription – Gemini Flash API extracts medicine names, dosage, and additional instructions.
|
| 28 |
+
|
| 29 |
+
- 💬 **Medical Chatbot Assistant**
|
| 30 |
+
Chat with a friendly AI named _MediSync_ to understand your medications, their purpose, and general health-related queries.
|
| 31 |
+
|
| 32 |
+
- ✨ **Structured Output**
|
| 33 |
+
Data is neatly parsed and presented to users in a patient-friendly format.
|
| 34 |
+
|
| 35 |
+
- 🚀 **Powered by Gen AI**
|
| 36 |
+
Uses Google's latest large language models (LLMs) from Vertex AI to process and reason with natural language.
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## 🧑⚕️ Use Case
|
| 41 |
+
|
| 42 |
+
In many **rural clinics**, patients receive handwritten prescriptions but often struggle to understand them. MediSync.AI bridges this gap using Gen AI, allowing users to:
|
| 43 |
+
|
| 44 |
+
- Understand medication names and dosages.
|
| 45 |
+
- Ask questions about medicines in natural language.
|
| 46 |
+
- Interact with a conversational assistant for basic medical advice (with disclaimers).
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## 🔧 Tech Stack
|
| 51 |
+
|
| 52 |
+
| Layer | Tech Used |
|
| 53 |
+
| ---------------- | ------------------------------------- |
|
| 54 |
+
| 🌐 Frontend | Gradio (Python-based interface) |
|
| 55 |
+
| 🧠 GenAI Backend | Gemini 2.0 Flash (via Vertex AI) |
|
| 56 |
+
| ☁️ Platform | Google Cloud (Vertex AI, Gemini APIs) |
|
| 57 |
+
| 🧪 Language | Python |
|
| 58 |
+
| 📁 File Handling | `requests`, `orjson`, `PIL`, etc. |
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
## 📌 Key Gemini Features Used
|
| 63 |
+
|
| 64 |
+
✅ Few-shot prompting
|
| 65 |
+
✅ Structured prompt engineering
|
| 66 |
+
✅ Document understanding (prescriptions)
|
| 67 |
+
✅ Conversational interface with memory
|
| 68 |
+
✅ Vertex AI managed model access (no fine-tuning required)
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## 🧠 How GenAI Solves the Problem
|
| 73 |
+
|
| 74 |
+
GenAI bridges the literacy and accessibility gap by:
|
| 75 |
+
|
| 76 |
+
- **Extracting structured medicine data** from unstructured prescription images.
|
| 77 |
+
- **Answering patient queries conversationally**, using large medical knowledge embedded in Gemini models.
|
| 78 |
+
- **Handling diverse handwriting**, typos, and low-context queries effectively.
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## 📂 File Structure
|
| 83 |
+
|
| 84 |
+
```
|
| 85 |
+
mediSync-AI/
|
| 86 |
+
│
|
| 87 |
+
├── main.ipynb # Jupyter notebook with the full GenAI flow
|
| 88 |
+
├── requirements.txt # Dependencies
|
| 89 |
+
├── data/
|
| 90 |
+
│ └── img1.jpg
|
| 91 |
+
│ └── img2.jpg
|
| 92 |
+
│ :
|
| 93 |
+
│ :
|
| 94 |
+
├── README.md
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
## ▶️ How to Run
|
| 100 |
+
|
| 101 |
+
1. Clone the repo
|
| 102 |
+
|
| 103 |
+
```bash
|
| 104 |
+
git clone https://github.com/Sarita-021/mediSync-AI.git
|
| 105 |
+
cd mediSync-AI
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
2. Install requirements
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
pip install -r requirements.txt
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
3. Run the notebook or script
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
jupyter notebook main.ipynb
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
4. Upload a prescription image & start chatting with the bot 🎯
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
## ⚠️ Disclaimer
|
| 125 |
+
|
| 126 |
+
> MediSync.AI does **not replace professional medical advice**. Always consult a licensed medical professional before taking any medication or making health-related decisions.
|
| 127 |
+
|
| 128 |
+
---
|
| 129 |
+
|
| 130 |
+
## 📸 Demo Screenshot
|
| 131 |
+
|
| 132 |
+

|
| 133 |
+
|
| 134 |
+

|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
## 🧑💻 Author
|
| 139 |
+
|
| 140 |
+
**Sarita** || Gen AI Intensive 2025Q1 Capstone Project || AI & ML Enthusiast
|
app.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import google.generativeai as genai
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
|
| 10 |
+
# Load environment variables
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# Get the API key from environment variable
|
| 14 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 15 |
+
|
| 16 |
+
# Configure the GenAI client
|
| 17 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 18 |
+
# Load the Gemini model
|
| 19 |
+
model = genai.GenerativeModel("gemini-2.0-flash")
|
| 20 |
+
#client = genai.Client()
|
| 21 |
+
|
| 22 |
+
# Prompt for image-based structured output
|
| 23 |
+
prompt = """
|
| 24 |
+
You are a medical assistant AI. Extract structured data from this handwritten prescription image.
|
| 25 |
+
|
| 26 |
+
Here are some common medicines there strength and usage
|
| 27 |
+
Medicine Name Strength Example Usage
|
| 28 |
+
Paracetamol 500mg, 650mg Pain relief, fever
|
| 29 |
+
Amoxicillin 250mg, 500mg Antibiotic
|
| 30 |
+
Azithromycin 250mg, 500mg Antibiotic
|
| 31 |
+
Ibuprofen 400mg, 600mg Pain relief, anti-inflammatory
|
| 32 |
+
Cefixime 200mg Antibiotic
|
| 33 |
+
Pantoprazole 40mg Acidity, ulcer prevention
|
| 34 |
+
Domperidone 10mg Anti-nausea
|
| 35 |
+
Metformin 500mg, 1000mg Diabetes
|
| 36 |
+
Amlodipine 5mg Blood pressure
|
| 37 |
+
Cetirizine 10mg Anti-allergy
|
| 38 |
+
Ranitidine 150mg Acidity
|
| 39 |
+
Dolo 650 650mg Fever, pain relief
|
| 40 |
+
Ondansetron 4mg, 8mg Anti-vomiting
|
| 41 |
+
Levocetirizine 5mg Allergy
|
| 42 |
+
Losartan 50mg Blood pressure
|
| 43 |
+
Clavulanic Acid 125mg (with Amox) Antibiotic combo
|
| 44 |
+
Salbutamol Inhaler/Syrup Asthma
|
| 45 |
+
|
| 46 |
+
Even if handwritten, try your best to extract medicine names, dosage frequency (like 1-0-1), and strength (mg).
|
| 47 |
+
|
| 48 |
+
Focus on extracting:
|
| 49 |
+
- Patient name
|
| 50 |
+
- List of medicines prescribed (Paracetamol)
|
| 51 |
+
- Strength (mg, ml, etc.)
|
| 52 |
+
- Dosage frequency (e.g., 1-0-1 or twice daily)
|
| 53 |
+
- Duration
|
| 54 |
+
- Additional notes
|
| 55 |
+
|
| 56 |
+
Return ONLY this JSON format:
|
| 57 |
+
{
|
| 58 |
+
"patient_name": "",
|
| 59 |
+
"medicines": [
|
| 60 |
+
{
|
| 61 |
+
"name": "",
|
| 62 |
+
"strength": "",
|
| 63 |
+
"dosage_frequency": "",
|
| 64 |
+
"duration": ""
|
| 65 |
+
}
|
| 66 |
+
],
|
| 67 |
+
"notes": ""
|
| 68 |
+
}
|
| 69 |
+
If any field is missing, return it as null.
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
# Function to handle image input
|
| 73 |
+
def extract_prescription(image):
|
| 74 |
+
if image is None:
|
| 75 |
+
return "Please upload an image."
|
| 76 |
+
|
| 77 |
+
#response = client.models.generate_content(
|
| 78 |
+
|
| 79 |
+
response = model.generate_content(
|
| 80 |
+
contents=[
|
| 81 |
+
prompt,
|
| 82 |
+
image
|
| 83 |
+
]
|
| 84 |
+
)
|
| 85 |
+
text = response.text.strip()
|
| 86 |
+
|
| 87 |
+
# Remove markdown formatting if any
|
| 88 |
+
if text.startswith("```json"):
|
| 89 |
+
text = re.sub(r"```json|```", "", text).strip()
|
| 90 |
+
|
| 91 |
+
try:
|
| 92 |
+
data = json.loads(text)
|
| 93 |
+
|
| 94 |
+
# Format nicely
|
| 95 |
+
output = f"### 👩⚕️ Prescription Summary\n"
|
| 96 |
+
output += f"- **Patient Name:** {data.get('patient_name', 'N/A') or 'N/A'}\n"
|
| 97 |
+
output += f"- **Medicines Prescribed:**\n"
|
| 98 |
+
|
| 99 |
+
for med in data.get("medicines", []):
|
| 100 |
+
name = med.get("name") or "Unknown"
|
| 101 |
+
strength = med.get("strength") or "N/A"
|
| 102 |
+
freq = med.get("dosage_frequency") or "N/A"
|
| 103 |
+
duration = med.get("duration") or "N/A"
|
| 104 |
+
output += f" - 💊 **{name}** – {strength} – Dosage: {freq} – Duration: {duration}\n"
|
| 105 |
+
|
| 106 |
+
notes = data.get("notes") or "None"
|
| 107 |
+
output += f"- **Notes:** {notes}\n"
|
| 108 |
+
|
| 109 |
+
return output
|
| 110 |
+
|
| 111 |
+
except Exception as e:
|
| 112 |
+
return f"❌ Error parsing response:\n{text}"
|
| 113 |
+
|
| 114 |
+
# Load Gemini Chat Model
|
| 115 |
+
chat = model.start_chat(history=[])
|
| 116 |
+
#chat = client.chats.create(model="gemini-2.0-flash")
|
| 117 |
+
|
| 118 |
+
# Define few-shot prompt to guide the agent
|
| 119 |
+
system_prompt = """
|
| 120 |
+
You are a friendly and knowledgeable AI medical assistant named MediSync.
|
| 121 |
+
You help patients understand their prescriptions, medications, and basic symptoms.
|
| 122 |
+
|
| 123 |
+
Example Q&A:
|
| 124 |
+
|
| 125 |
+
Q: I was prescribed Paracetamol 650mg. What is it for?
|
| 126 |
+
A: Paracetamol is used to relieve fever and mild to moderate pain, such as headaches or body aches.
|
| 127 |
+
|
| 128 |
+
Q: My prescription has Amoxicillin and Clavulanic acid. What condition could this be?
|
| 129 |
+
A: That combination is often used to treat bacterial infections like sinusitis, throat infections, or bronchitis.
|
| 130 |
+
|
| 131 |
+
Q: What medicine should I take for acidity?
|
| 132 |
+
A: Over-the-counter medicines like Pantoprazole or Ranitidine are commonly used for acidity. Please consult a doctor before taking any medication.
|
| 133 |
+
|
| 134 |
+
Always include a disclaimer like: "Please consult a licensed medical professional before taking any medication."
|
| 135 |
+
|
| 136 |
+
Start interacting now.
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
# Send system prompt to chat session
|
| 140 |
+
chat.send_message(system_prompt)
|
| 141 |
+
|
| 142 |
+
# Chatbot function
|
| 143 |
+
def chat_with_medisync(user_question, history):
|
| 144 |
+
try:
|
| 145 |
+
response = chat.send_message(user_question)
|
| 146 |
+
return response.text
|
| 147 |
+
except Exception as e:
|
| 148 |
+
return f"❌ Error: {e}"
|
| 149 |
+
|
| 150 |
+
# Gradio Interface
|
| 151 |
+
with gr.Blocks() as MediSyncAI:
|
| 152 |
+
gr.Markdown("## 🧠 MediSync.AI - Prescription Reader + Chatbot")
|
| 153 |
+
|
| 154 |
+
with gr.Tab("📸 Upload Prescription"):
|
| 155 |
+
with gr.Row():
|
| 156 |
+
image_input = gr.Image(type="pil", label="Upload Prescription Image")
|
| 157 |
+
json_output = gr.Markdown(label="Prescription Summary")
|
| 158 |
+
|
| 159 |
+
extract_btn = gr.Button("Extract Info")
|
| 160 |
+
extract_btn.click(fn=extract_prescription, inputs=image_input, outputs=json_output)
|
| 161 |
+
|
| 162 |
+
with gr.Tab("💬 Chat with MediSync"):
|
| 163 |
+
chatbot = gr.ChatInterface(
|
| 164 |
+
fn=chat_with_medisync,
|
| 165 |
+
type="messages",
|
| 166 |
+
title="MediSync-AI Chatbot",
|
| 167 |
+
chatbot=gr.Chatbot(label="MediSync"),
|
| 168 |
+
textbox=gr.Textbox(placeholder="Type your medical question here...", label="Your question"),
|
| 169 |
+
theme="compact",
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
#MediSyncAI.launch()
|
| 173 |
+
if __name__ == "__main__":
|
| 174 |
+
# Launch the Gradio app
|
| 175 |
+
MediSyncAI.launch(share=True, debug=True)
|
| 176 |
+
# Uncomment the line below to run the app locally without sharing
|
medisync-ai.ipynb
ADDED
|
@@ -0,0 +1,1135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "17843267",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
|
| 9 |
+
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
|
| 10 |
+
"execution": {
|
| 11 |
+
"iopub.execute_input": "2025-04-10T12:39:38.864941Z",
|
| 12 |
+
"iopub.status.busy": "2025-04-10T12:39:38.864173Z",
|
| 13 |
+
"iopub.status.idle": "2025-04-10T12:39:40.726212Z",
|
| 14 |
+
"shell.execute_reply": "2025-04-10T12:39:40.725272Z"
|
| 15 |
+
},
|
| 16 |
+
"papermill": {
|
| 17 |
+
"duration": 1.869524,
|
| 18 |
+
"end_time": "2025-04-10T12:39:40.727823",
|
| 19 |
+
"exception": false,
|
| 20 |
+
"start_time": "2025-04-10T12:39:38.858299",
|
| 21 |
+
"status": "completed"
|
| 22 |
+
},
|
| 23 |
+
"scrolled": true,
|
| 24 |
+
"tags": []
|
| 25 |
+
},
|
| 26 |
+
"outputs": [],
|
| 27 |
+
"source": [
|
| 28 |
+
"# This Python 3 environment comes with many helpful analytics libraries installed\n",
|
| 29 |
+
"# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n",
|
| 30 |
+
"# For example, here's several helpful packages to load\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"import numpy as np # linear algebra\n",
|
| 33 |
+
"import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
|
| 34 |
+
"\n",
|
| 35 |
+
"# Input data files are available in the read-only \"../input/\" directory\n",
|
| 36 |
+
"# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"# import os\n",
|
| 39 |
+
"# for dirname, _, filenames in os.walk('/kaggle/input'):\n",
|
| 40 |
+
"# for filename in filenames:\n",
|
| 41 |
+
"# print(os.path.join(dirname, filename))\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n",
|
| 44 |
+
"# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "markdown",
|
| 49 |
+
"id": "25998fd8",
|
| 50 |
+
"metadata": {
|
| 51 |
+
"papermill": {
|
| 52 |
+
"duration": 0.003574,
|
| 53 |
+
"end_time": "2025-04-10T12:39:40.735704",
|
| 54 |
+
"exception": false,
|
| 55 |
+
"start_time": "2025-04-10T12:39:40.732130",
|
| 56 |
+
"status": "completed"
|
| 57 |
+
},
|
| 58 |
+
"tags": []
|
| 59 |
+
},
|
| 60 |
+
"source": [
|
| 61 |
+
"# ❗ What is the Problem?\n",
|
| 62 |
+
"In many clinics—especially in rural or under-resourced areas—handwritten medical prescriptions remain the norm. These prescriptions are often:\n",
|
| 63 |
+
"\n",
|
| 64 |
+
"- Hard to read due to illegible handwriting\n",
|
| 65 |
+
"- Prone to misinterpretation, leading to wrong medications\n",
|
| 66 |
+
"- Difficult for patients to understand dosage, strength, and purpose of the medicines\n",
|
| 67 |
+
"- Lacking digitization, making tracking and processing inefficient\n",
|
| 68 |
+
"\n",
|
| 69 |
+
"These challenges not only affect patient safety but also create bottlenecks in pharmacy operations, telemedicine, and healthcare delivery.\n",
|
| 70 |
+
"\n",
|
| 71 |
+
"- There is a strong need for an intelligent, automated system that can:\n",
|
| 72 |
+
"- Accurately read and interpret handwritten prescriptions\n",
|
| 73 |
+
"- Extract relevant information in structured formats\n",
|
| 74 |
+
"- Assist patients with friendly explanations of what their prescriptions mean"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"cell_type": "markdown",
|
| 79 |
+
"id": "ac631bc5",
|
| 80 |
+
"metadata": {
|
| 81 |
+
"papermill": {
|
| 82 |
+
"duration": 0.003458,
|
| 83 |
+
"end_time": "2025-04-10T12:39:40.743150",
|
| 84 |
+
"exception": false,
|
| 85 |
+
"start_time": "2025-04-10T12:39:40.739692",
|
| 86 |
+
"status": "completed"
|
| 87 |
+
},
|
| 88 |
+
"tags": []
|
| 89 |
+
},
|
| 90 |
+
"source": [
|
| 91 |
+
"# 💡 Idea - MediSync.AI :\n",
|
| 92 |
+
"A generative AI-powered assistant that extracts handwritten prescriptions, retrieves drug information, checks for possible interactions, and provides simplified explanations — specifically designed for use in low-resource rural clinics.\n"
|
| 93 |
+
]
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"cell_type": "markdown",
|
| 97 |
+
"id": "d6a51b27",
|
| 98 |
+
"metadata": {
|
| 99 |
+
"papermill": {
|
| 100 |
+
"duration": 0.003648,
|
| 101 |
+
"end_time": "2025-04-10T12:39:40.750749",
|
| 102 |
+
"exception": false,
|
| 103 |
+
"start_time": "2025-04-10T12:39:40.747101",
|
| 104 |
+
"status": "completed"
|
| 105 |
+
},
|
| 106 |
+
"tags": []
|
| 107 |
+
},
|
| 108 |
+
"source": [
|
| 109 |
+
"# ❓ How can Gen AI solve the problem?\n",
|
| 110 |
+
"Handwritten medical prescriptions are often difficult to read and interpret, especially in rural or resource-constrained settings where access to qualified pharmacists is limited. Traditional OCR systems struggle with messy handwriting and lack contextual understanding. This is where Generative AI becomes powerful — it doesn't just extract text, it understands and structures the data meaningfully.\n",
|
| 111 |
+
"\n",
|
| 112 |
+
"By leveraging Google's Gemini-2.0-flash, a multimodal Gen AI model, the system can:\n",
|
| 113 |
+
"\n",
|
| 114 |
+
"- Understand handwritten prescription images\n",
|
| 115 |
+
"- Extract structured information like patient name, medicine names, strengths, dosage frequency, and additional notes\n",
|
| 116 |
+
"- Engage in interactive Q&A to explain medicines and symptoms to patients\n",
|
| 117 |
+
"\n",
|
| 118 |
+
"This significantly reduces manual effort, enhances accuracy, and makes healthcare more accessible — especially in rural clinics or telemedicine use cases."
|
| 119 |
+
]
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"cell_type": "markdown",
|
| 123 |
+
"id": "3c32b7cd",
|
| 124 |
+
"metadata": {
|
| 125 |
+
"papermill": {
|
| 126 |
+
"duration": 0.003501,
|
| 127 |
+
"end_time": "2025-04-10T12:39:40.758115",
|
| 128 |
+
"exception": false,
|
| 129 |
+
"start_time": "2025-04-10T12:39:40.754614",
|
| 130 |
+
"status": "completed"
|
| 131 |
+
},
|
| 132 |
+
"tags": []
|
| 133 |
+
},
|
| 134 |
+
"source": [
|
| 135 |
+
"# 🧠 How is the problem solved in code with Gen AI?\n",
|
| 136 |
+
"The solution is implemented step-by-step using Python and Gemini APIs:\n",
|
| 137 |
+
"\n",
|
| 138 |
+
"1. **Image Input & Validation:**\n",
|
| 139 |
+
" The image is read using cv2 and validated before being sent to the model.\n",
|
| 140 |
+
"\n",
|
| 141 |
+
"2. **Prompt Engineering:**\n",
|
| 142 |
+
" A detailed prompt is crafted to instruct Gemini on how to extract and return information in a strict JSON format, including medicine names, dosage, duration, and patient name.\n",
|
| 143 |
+
"\n",
|
| 144 |
+
"3. **Calling Gemini-2.0-Flash:**\n",
|
| 145 |
+
" The image and prompt are passed to Gemini using generate_content(), which returns a structured response based on its understanding of the prescription.\n",
|
| 146 |
+
"\n",
|
| 147 |
+
"4. **Parsing & Display:**\n",
|
| 148 |
+
" The JSON output is parsed and the information is neatly formatted using Gradio to display patient info and prescriptions in a user-friendly manner.\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"5. **Chatbot Integration:**\n",
|
| 151 |
+
" A separate chat module is created using Gemini’s chat model. Few-shot examples guide the chatbot to answer health-related questions, explain prescribed medicines, and provide recommendations with a medical disclaimer.\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"This seamless integration of multimodal Gen AI + chat interface makes the system intelligent, helpful, and highly usable in real-world medical settings.\n",
|
| 154 |
+
"\n"
|
| 155 |
+
]
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"cell_type": "markdown",
|
| 159 |
+
"id": "8e450402",
|
| 160 |
+
"metadata": {
|
| 161 |
+
"papermill": {
|
| 162 |
+
"duration": 0.003449,
|
| 163 |
+
"end_time": "2025-04-10T12:39:40.765249",
|
| 164 |
+
"exception": false,
|
| 165 |
+
"start_time": "2025-04-10T12:39:40.761800",
|
| 166 |
+
"status": "completed"
|
| 167 |
+
},
|
| 168 |
+
"tags": []
|
| 169 |
+
},
|
| 170 |
+
"source": [
|
| 171 |
+
"# 👩🏻💻 Code Implementation"
|
| 172 |
+
]
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"cell_type": "markdown",
|
| 176 |
+
"id": "81fbb980",
|
| 177 |
+
"metadata": {
|
| 178 |
+
"papermill": {
|
| 179 |
+
"duration": 0.00343,
|
| 180 |
+
"end_time": "2025-04-10T12:39:40.772448",
|
| 181 |
+
"exception": false,
|
| 182 |
+
"start_time": "2025-04-10T12:39:40.769018",
|
| 183 |
+
"status": "completed"
|
| 184 |
+
},
|
| 185 |
+
"tags": []
|
| 186 |
+
},
|
| 187 |
+
"source": [
|
| 188 |
+
"**GenAI Capabilities Covered:**\n",
|
| 189 |
+
"\n",
|
| 190 |
+
"-> Structured output/JSON mode/controlled generation\n",
|
| 191 |
+
"\n",
|
| 192 |
+
"-> Few-shot prompting\n",
|
| 193 |
+
"\n",
|
| 194 |
+
"-> Image understanding\n",
|
| 195 |
+
"\n",
|
| 196 |
+
"-> Chatbot / Agents\n",
|
| 197 |
+
"\n",
|
| 198 |
+
"-> Long context window\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"-> Function Calling\n",
|
| 201 |
+
"\n",
|
| 202 |
+
"-> Document understanding"
|
| 203 |
+
]
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"cell_type": "code",
|
| 207 |
+
"execution_count": 2,
|
| 208 |
+
"id": "021fda3e",
|
| 209 |
+
"metadata": {
|
| 210 |
+
"execution": {
|
| 211 |
+
"iopub.execute_input": "2025-04-10T12:39:40.781233Z",
|
| 212 |
+
"iopub.status.busy": "2025-04-10T12:39:40.780771Z",
|
| 213 |
+
"iopub.status.idle": "2025-04-10T12:41:24.720680Z",
|
| 214 |
+
"shell.execute_reply": "2025-04-10T12:41:24.719694Z"
|
| 215 |
+
},
|
| 216 |
+
"papermill": {
|
| 217 |
+
"duration": 103.946402,
|
| 218 |
+
"end_time": "2025-04-10T12:41:24.722539",
|
| 219 |
+
"exception": false,
|
| 220 |
+
"start_time": "2025-04-10T12:39:40.776137",
|
| 221 |
+
"status": "completed"
|
| 222 |
+
},
|
| 223 |
+
"scrolled": true,
|
| 224 |
+
"tags": []
|
| 225 |
+
},
|
| 226 |
+
"outputs": [
|
| 227 |
+
{
|
| 228 |
+
"name": "stdout",
|
| 229 |
+
"output_type": "stream",
|
| 230 |
+
"text": [
|
| 231 |
+
"Requirement already satisfied: easyocr in /usr/local/lib/python3.11/dist-packages (1.7.2)\r\n",
|
| 232 |
+
"Requirement already satisfied: torch in /usr/local/lib/python3.11/dist-packages (from easyocr) (2.5.1+cu124)\r\n",
|
| 233 |
+
"Requirement already satisfied: torchvision>=0.5 in /usr/local/lib/python3.11/dist-packages (from easyocr) (0.20.1+cu124)\r\n",
|
| 234 |
+
"Requirement already satisfied: opencv-python-headless in /usr/local/lib/python3.11/dist-packages (from easyocr) (4.11.0.86)\r\n",
|
| 235 |
+
"Requirement already satisfied: scipy in /usr/local/lib/python3.11/dist-packages (from easyocr) (1.15.2)\r\n",
|
| 236 |
+
"Requirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (from easyocr) (1.26.4)\r\n",
|
| 237 |
+
"Requirement already satisfied: Pillow in /usr/local/lib/python3.11/dist-packages (from easyocr) (11.1.0)\r\n",
|
| 238 |
+
"Requirement already satisfied: scikit-image in /usr/local/lib/python3.11/dist-packages (from easyocr) (0.25.1)\r\n",
|
| 239 |
+
"Requirement already satisfied: python-bidi in /usr/local/lib/python3.11/dist-packages (from easyocr) (0.6.6)\r\n",
|
| 240 |
+
"Requirement already satisfied: PyYAML in /usr/local/lib/python3.11/dist-packages (from easyocr) (6.0.2)\r\n",
|
| 241 |
+
"Requirement already satisfied: Shapely in /usr/local/lib/python3.11/dist-packages (from easyocr) (2.1.0)\r\n",
|
| 242 |
+
"Requirement already satisfied: pyclipper in /usr/local/lib/python3.11/dist-packages (from easyocr) (1.3.0.post6)\r\n",
|
| 243 |
+
"Requirement already satisfied: ninja in /usr/local/lib/python3.11/dist-packages (from easyocr) (1.11.1.4)\r\n",
|
| 244 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (3.18.0)\r\n",
|
| 245 |
+
"Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (4.13.1)\r\n",
|
| 246 |
+
"Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (3.4.2)\r\n",
|
| 247 |
+
"Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (3.1.6)\r\n",
|
| 248 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (2025.3.2)\r\n",
|
| 249 |
+
"Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (12.4.127)\r\n",
|
| 250 |
+
"Requirement already satisfied: nvidia-cuda-runtime-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (12.4.127)\r\n",
|
| 251 |
+
"Requirement already satisfied: nvidia-cuda-cupti-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (12.4.127)\r\n",
|
| 252 |
+
"Collecting nvidia-cudnn-cu12==9.1.0.70 (from torch->easyocr)\r\n",
|
| 253 |
+
" Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\r\n",
|
| 254 |
+
"Collecting nvidia-cublas-cu12==12.4.5.8 (from torch->easyocr)\r\n",
|
| 255 |
+
" Downloading nvidia_cublas_cu12-12.4.5.8-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\r\n",
|
| 256 |
+
"Collecting nvidia-cufft-cu12==11.2.1.3 (from torch->easyocr)\r\n",
|
| 257 |
+
" Downloading nvidia_cufft_cu12-11.2.1.3-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\r\n",
|
| 258 |
+
"Collecting nvidia-curand-cu12==10.3.5.147 (from torch->easyocr)\r\n",
|
| 259 |
+
" Downloading nvidia_curand_cu12-10.3.5.147-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\r\n",
|
| 260 |
+
"Collecting nvidia-cusolver-cu12==11.6.1.9 (from torch->easyocr)\r\n",
|
| 261 |
+
" Downloading nvidia_cusolver_cu12-11.6.1.9-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\r\n",
|
| 262 |
+
"Collecting nvidia-cusparse-cu12==12.3.1.170 (from torch->easyocr)\r\n",
|
| 263 |
+
" Downloading nvidia_cusparse_cu12-12.3.1.170-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\r\n",
|
| 264 |
+
"Requirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (2.21.5)\r\n",
|
| 265 |
+
"Requirement already satisfied: nvidia-nvtx-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (12.4.127)\r\n",
|
| 266 |
+
"Collecting nvidia-nvjitlink-cu12==12.4.127 (from torch->easyocr)\r\n",
|
| 267 |
+
" Downloading nvidia_nvjitlink_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\r\n",
|
| 268 |
+
"Requirement already satisfied: triton==3.1.0 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (3.1.0)\r\n",
|
| 269 |
+
"Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch->easyocr) (1.13.1)\r\n",
|
| 270 |
+
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch->easyocr) (1.3.0)\r\n",
|
| 271 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy->easyocr) (1.3.8)\r\n",
|
| 272 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy->easyocr) (1.2.4)\r\n",
|
| 273 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy->easyocr) (0.1.1)\r\n",
|
| 274 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy->easyocr) (2025.1.0)\r\n",
|
| 275 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy->easyocr) (2022.1.0)\r\n",
|
| 276 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy->easyocr) (2.4.1)\r\n",
|
| 277 |
+
"Requirement already satisfied: imageio!=2.35.0,>=2.33 in /usr/local/lib/python3.11/dist-packages (from scikit-image->easyocr) (2.37.0)\r\n",
|
| 278 |
+
"Requirement already satisfied: tifffile>=2022.8.12 in /usr/local/lib/python3.11/dist-packages (from scikit-image->easyocr) (2025.1.10)\r\n",
|
| 279 |
+
"Requirement already satisfied: packaging>=21 in /usr/local/lib/python3.11/dist-packages (from scikit-image->easyocr) (24.2)\r\n",
|
| 280 |
+
"Requirement already satisfied: lazy-loader>=0.4 in /usr/local/lib/python3.11/dist-packages (from scikit-image->easyocr) (0.4)\r\n",
|
| 281 |
+
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch->easyocr) (3.0.2)\r\n",
|
| 282 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy->easyocr) (2024.2.0)\r\n",
|
| 283 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy->easyocr) (2022.1.0)\r\n",
|
| 284 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy->easyocr) (1.2.0)\r\n",
|
| 285 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy->easyocr) (2024.2.0)\r\n",
|
| 286 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy->easyocr) (2024.2.0)\r\n",
|
| 287 |
+
"Downloading nvidia_cublas_cu12-12.4.5.8-py3-none-manylinux2014_x86_64.whl (363.4 MB)\r\n",
|
| 288 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m363.4/363.4 MB\u001b[0m \u001b[31m4.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 289 |
+
"\u001b[?25hDownloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)\r\n",
|
| 290 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m664.8/664.8 MB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 291 |
+
"\u001b[?25hDownloading nvidia_cufft_cu12-11.2.1.3-py3-none-manylinux2014_x86_64.whl (211.5 MB)\r\n",
|
| 292 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.5/211.5 MB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 293 |
+
"\u001b[?25hDownloading nvidia_curand_cu12-10.3.5.147-py3-none-manylinux2014_x86_64.whl (56.3 MB)\r\n",
|
| 294 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.3/56.3 MB\u001b[0m \u001b[31m30.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 295 |
+
"\u001b[?25hDownloading nvidia_cusolver_cu12-11.6.1.9-py3-none-manylinux2014_x86_64.whl (127.9 MB)\r\n",
|
| 296 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m127.9/127.9 MB\u001b[0m \u001b[31m12.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 297 |
+
"\u001b[?25hDownloading nvidia_cusparse_cu12-12.3.1.170-py3-none-manylinux2014_x86_64.whl (207.5 MB)\r\n",
|
| 298 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.5/207.5 MB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 299 |
+
"\u001b[?25hDownloading nvidia_nvjitlink_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (21.1 MB)\r\n",
|
| 300 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.1/21.1 MB\u001b[0m \u001b[31m79.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 301 |
+
"\u001b[?25hInstalling collected packages: nvidia-nvjitlink-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cublas-cu12, nvidia-cusparse-cu12, nvidia-cudnn-cu12, nvidia-cusolver-cu12\r\n",
|
| 302 |
+
" Attempting uninstall: nvidia-nvjitlink-cu12\r\n",
|
| 303 |
+
" Found existing installation: nvidia-nvjitlink-cu12 12.8.93\r\n",
|
| 304 |
+
" Uninstalling nvidia-nvjitlink-cu12-12.8.93:\r\n",
|
| 305 |
+
" Successfully uninstalled nvidia-nvjitlink-cu12-12.8.93\r\n",
|
| 306 |
+
" Attempting uninstall: nvidia-curand-cu12\r\n",
|
| 307 |
+
" Found existing installation: nvidia-curand-cu12 10.3.9.90\r\n",
|
| 308 |
+
" Uninstalling nvidia-curand-cu12-10.3.9.90:\r\n",
|
| 309 |
+
" Successfully uninstalled nvidia-curand-cu12-10.3.9.90\r\n",
|
| 310 |
+
" Attempting uninstall: nvidia-cufft-cu12\r\n",
|
| 311 |
+
" Found existing installation: nvidia-cufft-cu12 11.3.3.83\r\n",
|
| 312 |
+
" Uninstalling nvidia-cufft-cu12-11.3.3.83:\r\n",
|
| 313 |
+
" Successfully uninstalled nvidia-cufft-cu12-11.3.3.83\r\n",
|
| 314 |
+
" Attempting uninstall: nvidia-cublas-cu12\r\n",
|
| 315 |
+
" Found existing installation: nvidia-cublas-cu12 12.8.4.1\r\n",
|
| 316 |
+
" Uninstalling nvidia-cublas-cu12-12.8.4.1:\r\n",
|
| 317 |
+
" Successfully uninstalled nvidia-cublas-cu12-12.8.4.1\r\n",
|
| 318 |
+
" Attempting uninstall: nvidia-cusparse-cu12\r\n",
|
| 319 |
+
" Found existing installation: nvidia-cusparse-cu12 12.5.8.93\r\n",
|
| 320 |
+
" Uninstalling nvidia-cusparse-cu12-12.5.8.93:\r\n",
|
| 321 |
+
" Successfully uninstalled nvidia-cusparse-cu12-12.5.8.93\r\n",
|
| 322 |
+
" Attempting uninstall: nvidia-cudnn-cu12\r\n",
|
| 323 |
+
" Found existing installation: nvidia-cudnn-cu12 9.3.0.75\r\n",
|
| 324 |
+
" Uninstalling nvidia-cudnn-cu12-9.3.0.75:\r\n",
|
| 325 |
+
" Successfully uninstalled nvidia-cudnn-cu12-9.3.0.75\r\n",
|
| 326 |
+
" Attempting uninstall: nvidia-cusolver-cu12\r\n",
|
| 327 |
+
" Found existing installation: nvidia-cusolver-cu12 11.7.3.90\r\n",
|
| 328 |
+
" Uninstalling nvidia-cusolver-cu12-11.7.3.90:\r\n",
|
| 329 |
+
" Successfully uninstalled nvidia-cusolver-cu12-11.7.3.90\r\n",
|
| 330 |
+
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\r\n",
|
| 331 |
+
"pylibcugraph-cu12 24.12.0 requires pylibraft-cu12==24.12.*, but you have pylibraft-cu12 25.2.0 which is incompatible.\r\n",
|
| 332 |
+
"pylibcugraph-cu12 24.12.0 requires rmm-cu12==24.12.*, but you have rmm-cu12 25.2.0 which is incompatible.\u001b[0m\u001b[31m\r\n",
|
| 333 |
+
"\u001b[0mSuccessfully installed nvidia-cublas-cu12-12.4.5.8 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.2.1.3 nvidia-curand-cu12-10.3.5.147 nvidia-cusolver-cu12-11.6.1.9 nvidia-cusparse-cu12-12.3.1.170 nvidia-nvjitlink-cu12-12.4.127\r\n",
|
| 334 |
+
"Requirement already satisfied: sentence-transformers in /usr/local/lib/python3.11/dist-packages (3.4.1)\r\n",
|
| 335 |
+
"Collecting faiss-cpu\r\n",
|
| 336 |
+
" Downloading faiss_cpu-1.10.0-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (4.4 kB)\r\n",
|
| 337 |
+
"Requirement already satisfied: transformers<5.0.0,>=4.41.0 in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (4.51.1)\r\n",
|
| 338 |
+
"Requirement already satisfied: tqdm in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (4.67.1)\r\n",
|
| 339 |
+
"Requirement already satisfied: torch>=1.11.0 in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (2.5.1+cu124)\r\n",
|
| 340 |
+
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (1.2.2)\r\n",
|
| 341 |
+
"Requirement already satisfied: scipy in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (1.15.2)\r\n",
|
| 342 |
+
"Requirement already satisfied: huggingface-hub>=0.20.0 in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (0.30.2)\r\n",
|
| 343 |
+
"Requirement already satisfied: Pillow in /usr/local/lib/python3.11/dist-packages (from sentence-transformers) (11.1.0)\r\n",
|
| 344 |
+
"Requirement already satisfied: numpy<3.0,>=1.25.0 in /usr/local/lib/python3.11/dist-packages (from faiss-cpu) (1.26.4)\r\n",
|
| 345 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from faiss-cpu) (24.2)\r\n",
|
| 346 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.20.0->sentence-transformers) (3.18.0)\r\n",
|
| 347 |
+
"Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.20.0->sentence-transformers) (2025.3.2)\r\n",
|
| 348 |
+
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.20.0->sentence-transformers) (6.0.2)\r\n",
|
| 349 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.20.0->sentence-transformers) (2.32.3)\r\n",
|
| 350 |
+
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.20.0->sentence-transformers) (4.13.1)\r\n",
|
| 351 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.25.0->faiss-cpu) (1.3.8)\r\n",
|
| 352 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.25.0->faiss-cpu) (1.2.4)\r\n",
|
| 353 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.25.0->faiss-cpu) (0.1.1)\r\n",
|
| 354 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.25.0->faiss-cpu) (2025.1.0)\r\n",
|
| 355 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.25.0->faiss-cpu) (2022.1.0)\r\n",
|
| 356 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.25.0->faiss-cpu) (2.4.1)\r\n",
|
| 357 |
+
"Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (3.4.2)\r\n",
|
| 358 |
+
"Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (3.1.6)\r\n",
|
| 359 |
+
"Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.4.127)\r\n",
|
| 360 |
+
"Requirement already satisfied: nvidia-cuda-runtime-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.4.127)\r\n",
|
| 361 |
+
"Requirement already satisfied: nvidia-cuda-cupti-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.4.127)\r\n",
|
| 362 |
+
"Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (9.1.0.70)\r\n",
|
| 363 |
+
"Requirement already satisfied: nvidia-cublas-cu12==12.4.5.8 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.4.5.8)\r\n",
|
| 364 |
+
"Requirement already satisfied: nvidia-cufft-cu12==11.2.1.3 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (11.2.1.3)\r\n",
|
| 365 |
+
"Requirement already satisfied: nvidia-curand-cu12==10.3.5.147 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (10.3.5.147)\r\n",
|
| 366 |
+
"Requirement already satisfied: nvidia-cusolver-cu12==11.6.1.9 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (11.6.1.9)\r\n",
|
| 367 |
+
"Requirement already satisfied: nvidia-cusparse-cu12==12.3.1.170 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.3.1.170)\r\n",
|
| 368 |
+
"Requirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (2.21.5)\r\n",
|
| 369 |
+
"Requirement already satisfied: nvidia-nvtx-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.4.127)\r\n",
|
| 370 |
+
"Requirement already satisfied: nvidia-nvjitlink-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (12.4.127)\r\n",
|
| 371 |
+
"Requirement already satisfied: triton==3.1.0 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (3.1.0)\r\n",
|
| 372 |
+
"Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch>=1.11.0->sentence-transformers) (1.13.1)\r\n",
|
| 373 |
+
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch>=1.11.0->sentence-transformers) (1.3.0)\r\n",
|
| 374 |
+
"Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.11/dist-packages (from transformers<5.0.0,>=4.41.0->sentence-transformers) (2024.11.6)\r\n",
|
| 375 |
+
"Requirement already satisfied: tokenizers<0.22,>=0.21 in /usr/local/lib/python3.11/dist-packages (from transformers<5.0.0,>=4.41.0->sentence-transformers) (0.21.0)\r\n",
|
| 376 |
+
"Requirement already satisfied: safetensors>=0.4.3 in /usr/local/lib/python3.11/dist-packages (from transformers<5.0.0,>=4.41.0->sentence-transformers) (0.5.2)\r\n",
|
| 377 |
+
"Requirement already satisfied: joblib>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from scikit-learn->sentence-transformers) (1.4.2)\r\n",
|
| 378 |
+
"Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn->sentence-transformers) (3.6.0)\r\n",
|
| 379 |
+
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch>=1.11.0->sentence-transformers) (3.0.2)\r\n",
|
| 380 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy<3.0,>=1.25.0->faiss-cpu) (2024.2.0)\r\n",
|
| 381 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy<3.0,>=1.25.0->faiss-cpu) (2022.1.0)\r\n",
|
| 382 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy<3.0,>=1.25.0->faiss-cpu) (1.2.0)\r\n",
|
| 383 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy<3.0,>=1.25.0->faiss-cpu) (2024.2.0)\r\n",
|
| 384 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.20.0->sentence-transformers) (3.4.1)\r\n",
|
| 385 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.20.0->sentence-transformers) (3.10)\r\n",
|
| 386 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.20.0->sentence-transformers) (2.3.0)\r\n",
|
| 387 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.20.0->sentence-transformers) (2025.1.31)\r\n",
|
| 388 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy<3.0,>=1.25.0->faiss-cpu) (2024.2.0)\r\n",
|
| 389 |
+
"Downloading faiss_cpu-1.10.0-cp311-cp311-manylinux_2_28_x86_64.whl (30.7 MB)\r\n",
|
| 390 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m30.7/30.7 MB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 391 |
+
"\u001b[?25hInstalling collected packages: faiss-cpu\r\n",
|
| 392 |
+
"Successfully installed faiss-cpu-1.10.0\r\n",
|
| 393 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m144.7/144.7 kB\u001b[0m \u001b[31m4.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 394 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m100.9/100.9 kB\u001b[0m \u001b[31m5.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 395 |
+
"\u001b[?25hCollecting gradio\r\n",
|
| 396 |
+
" Downloading gradio-5.24.0-py3-none-any.whl.metadata (16 kB)\r\n",
|
| 397 |
+
"Requirement already satisfied: aiofiles<25.0,>=22.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (22.1.0)\r\n",
|
| 398 |
+
"Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (4.9.0)\r\n",
|
| 399 |
+
"Collecting fastapi<1.0,>=0.115.2 (from gradio)\r\n",
|
| 400 |
+
" Downloading fastapi-0.115.12-py3-none-any.whl.metadata (27 kB)\r\n",
|
| 401 |
+
"Collecting ffmpy (from gradio)\r\n",
|
| 402 |
+
" Downloading ffmpy-0.5.0-py3-none-any.whl.metadata (3.0 kB)\r\n",
|
| 403 |
+
"Collecting gradio-client==1.8.0 (from gradio)\r\n",
|
| 404 |
+
" Downloading gradio_client-1.8.0-py3-none-any.whl.metadata (7.1 kB)\r\n",
|
| 405 |
+
"Collecting groovy~=0.1 (from gradio)\r\n",
|
| 406 |
+
" Downloading groovy-0.1.2-py3-none-any.whl.metadata (6.1 kB)\r\n",
|
| 407 |
+
"Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.11/dist-packages (from gradio) (0.28.1)\r\n",
|
| 408 |
+
"Requirement already satisfied: huggingface-hub>=0.28.1 in /usr/local/lib/python3.11/dist-packages (from gradio) (0.30.2)\r\n",
|
| 409 |
+
"Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (3.1.6)\r\n",
|
| 410 |
+
"Requirement already satisfied: markupsafe<4.0,>=2.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (3.0.2)\r\n",
|
| 411 |
+
"Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (1.26.4)\r\n",
|
| 412 |
+
"Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (3.10.15)\r\n",
|
| 413 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from gradio) (24.2)\r\n",
|
| 414 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (2.2.3)\r\n",
|
| 415 |
+
"Requirement already satisfied: pillow<12.0,>=8.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (11.1.0)\r\n",
|
| 416 |
+
"Requirement already satisfied: pydantic<2.12,>=2.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (2.11.3)\r\n",
|
| 417 |
+
"Requirement already satisfied: pydub in /usr/local/lib/python3.11/dist-packages (from gradio) (0.25.1)\r\n",
|
| 418 |
+
"Collecting python-multipart>=0.0.18 (from gradio)\r\n",
|
| 419 |
+
" Downloading python_multipart-0.0.20-py3-none-any.whl.metadata (1.8 kB)\r\n",
|
| 420 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (6.0.2)\r\n",
|
| 421 |
+
"Collecting ruff>=0.9.3 (from gradio)\r\n",
|
| 422 |
+
" Downloading ruff-0.11.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (25 kB)\r\n",
|
| 423 |
+
"Collecting safehttpx<0.2.0,>=0.1.6 (from gradio)\r\n",
|
| 424 |
+
" Downloading safehttpx-0.1.6-py3-none-any.whl.metadata (4.2 kB)\r\n",
|
| 425 |
+
"Collecting semantic-version~=2.0 (from gradio)\r\n",
|
| 426 |
+
" Downloading semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)\r\n",
|
| 427 |
+
"Collecting starlette<1.0,>=0.40.0 (from gradio)\r\n",
|
| 428 |
+
" Downloading starlette-0.46.1-py3-none-any.whl.metadata (6.2 kB)\r\n",
|
| 429 |
+
"Collecting tomlkit<0.14.0,>=0.12.0 (from gradio)\r\n",
|
| 430 |
+
" Downloading tomlkit-0.13.2-py3-none-any.whl.metadata (2.7 kB)\r\n",
|
| 431 |
+
"Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.11/dist-packages (from gradio) (0.15.1)\r\n",
|
| 432 |
+
"Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (4.13.1)\r\n",
|
| 433 |
+
"Collecting uvicorn>=0.14.0 (from gradio)\r\n",
|
| 434 |
+
" Downloading uvicorn-0.34.0-py3-none-any.whl.metadata (6.5 kB)\r\n",
|
| 435 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.11/dist-packages (from gradio-client==1.8.0->gradio) (2025.3.2)\r\n",
|
| 436 |
+
"Requirement already satisfied: websockets<16.0,>=10.0 in /usr/local/lib/python3.11/dist-packages (from gradio-client==1.8.0->gradio) (14.2)\r\n",
|
| 437 |
+
"Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.11/dist-packages (from anyio<5.0,>=3.0->gradio) (3.10)\r\n",
|
| 438 |
+
"Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.11/dist-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\r\n",
|
| 439 |
+
"Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from httpx>=0.24.1->gradio) (2025.1.31)\r\n",
|
| 440 |
+
"Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx>=0.24.1->gradio) (1.0.7)\r\n",
|
| 441 |
+
"Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\r\n",
|
| 442 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (3.18.0)\r\n",
|
| 443 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (2.32.3)\r\n",
|
| 444 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (4.67.1)\r\n",
|
| 445 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (1.3.8)\r\n",
|
| 446 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (1.2.4)\r\n",
|
| 447 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (0.1.1)\r\n",
|
| 448 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (2025.1.0)\r\n",
|
| 449 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (2022.1.0)\r\n",
|
| 450 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (2.4.1)\r\n",
|
| 451 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas<3.0,>=1.0->gradio) (2.9.0.post0)\r\n",
|
| 452 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas<3.0,>=1.0->gradio) (2025.2)\r\n",
|
| 453 |
+
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas<3.0,>=1.0->gradio) (2025.2)\r\n",
|
| 454 |
+
"Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<2.12,>=2.0->gradio) (0.7.0)\r\n",
|
| 455 |
+
"Requirement already satisfied: pydantic-core==2.33.1 in /usr/local/lib/python3.11/dist-packages (from pydantic<2.12,>=2.0->gradio) (2.33.1)\r\n",
|
| 456 |
+
"Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<2.12,>=2.0->gradio) (0.4.0)\r\n",
|
| 457 |
+
"Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.11/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.8)\r\n",
|
| 458 |
+
"Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.11/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\r\n",
|
| 459 |
+
"Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.11/dist-packages (from typer<1.0,>=0.12->gradio) (14.0.0)\r\n",
|
| 460 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.17.0)\r\n",
|
| 461 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.11/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\r\n",
|
| 462 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.11/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.19.1)\r\n",
|
| 463 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy<3.0,>=1.0->gradio) (2024.2.0)\r\n",
|
| 464 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy<3.0,>=1.0->gradio) (2022.1.0)\r\n",
|
| 465 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy<3.0,>=1.0->gradio) (1.2.0)\r\n",
|
| 466 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy<3.0,>=1.0->gradio) (2024.2.0)\r\n",
|
| 467 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.28.1->gradio) (3.4.1)\r\n",
|
| 468 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.28.1->gradio) (2.3.0)\r\n",
|
| 469 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy<3.0,>=1.0->gradio) (2024.2.0)\r\n",
|
| 470 |
+
"Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.11/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\r\n",
|
| 471 |
+
"Downloading gradio-5.24.0-py3-none-any.whl (46.9 MB)\r\n",
|
| 472 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.9/46.9 MB\u001b[0m \u001b[31m38.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 473 |
+
"\u001b[?25hDownloading gradio_client-1.8.0-py3-none-any.whl (322 kB)\r\n",
|
| 474 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m322.2/322.2 kB\u001b[0m \u001b[31m16.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 475 |
+
"\u001b[?25hDownloading fastapi-0.115.12-py3-none-any.whl (95 kB)\r\n",
|
| 476 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m95.2/95.2 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 477 |
+
"\u001b[?25hDownloading groovy-0.1.2-py3-none-any.whl (14 kB)\r\n",
|
| 478 |
+
"Downloading python_multipart-0.0.20-py3-none-any.whl (24 kB)\r\n",
|
| 479 |
+
"Downloading ruff-0.11.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.3 MB)\r\n",
|
| 480 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.3/11.3 MB\u001b[0m \u001b[31m110.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 481 |
+
"\u001b[?25hDownloading safehttpx-0.1.6-py3-none-any.whl (8.7 kB)\r\n",
|
| 482 |
+
"Downloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\r\n",
|
| 483 |
+
"Downloading starlette-0.46.1-py3-none-any.whl (71 kB)\r\n",
|
| 484 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m72.0/72.0 kB\u001b[0m \u001b[31m4.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 485 |
+
"\u001b[?25hDownloading tomlkit-0.13.2-py3-none-any.whl (37 kB)\r\n",
|
| 486 |
+
"Downloading uvicorn-0.34.0-py3-none-any.whl (62 kB)\r\n",
|
| 487 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.3/62.3 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\r\n",
|
| 488 |
+
"\u001b[?25hDownloading ffmpy-0.5.0-py3-none-any.whl (6.0 kB)\r\n",
|
| 489 |
+
"Installing collected packages: uvicorn, tomlkit, semantic-version, ruff, python-multipart, groovy, ffmpy, starlette, safehttpx, gradio-client, fastapi, gradio\r\n",
|
| 490 |
+
"Successfully installed fastapi-0.115.12 ffmpy-0.5.0 gradio-5.24.0 gradio-client-1.8.0 groovy-0.1.2 python-multipart-0.0.20 ruff-0.11.4 safehttpx-0.1.6 semantic-version-2.10.0 starlette-0.46.1 tomlkit-0.13.2 uvicorn-0.34.0\r\n"
|
| 491 |
+
]
|
| 492 |
+
}
|
| 493 |
+
],
|
| 494 |
+
"source": [
|
| 495 |
+
"# Install and import necessary libraries\n",
|
| 496 |
+
"!pip install easyocr\n",
|
| 497 |
+
"!pip install sentence-transformers faiss-cpu\n",
|
| 498 |
+
"!pip install -U -q \"google-genai==1.7.0\" # Install latest Google GenAI SDK\n",
|
| 499 |
+
"!pip install gradio # To quickly build and share interactive web interfaces"
|
| 500 |
+
]
|
| 501 |
+
},
|
| 502 |
+
{
|
| 503 |
+
"cell_type": "markdown",
|
| 504 |
+
"id": "585b1ccf",
|
| 505 |
+
"metadata": {
|
| 506 |
+
"papermill": {
|
| 507 |
+
"duration": 0.035728,
|
| 508 |
+
"end_time": "2025-04-10T12:41:24.794543",
|
| 509 |
+
"exception": false,
|
| 510 |
+
"start_time": "2025-04-10T12:41:24.758815",
|
| 511 |
+
"status": "completed"
|
| 512 |
+
},
|
| 513 |
+
"tags": []
|
| 514 |
+
},
|
| 515 |
+
"source": [
|
| 516 |
+
"## Step 1: Import necessary Libraries"
|
| 517 |
+
]
|
| 518 |
+
},
|
| 519 |
+
{
|
| 520 |
+
"cell_type": "code",
|
| 521 |
+
"execution_count": 3,
|
| 522 |
+
"id": "3d1d9fa3",
|
| 523 |
+
"metadata": {
|
| 524 |
+
"execution": {
|
| 525 |
+
"iopub.execute_input": "2025-04-10T12:41:24.870584Z",
|
| 526 |
+
"iopub.status.busy": "2025-04-10T12:41:24.870261Z",
|
| 527 |
+
"iopub.status.idle": "2025-04-10T12:41:41.412768Z",
|
| 528 |
+
"shell.execute_reply": "2025-04-10T12:41:41.411737Z"
|
| 529 |
+
},
|
| 530 |
+
"papermill": {
|
| 531 |
+
"duration": 16.583233,
|
| 532 |
+
"end_time": "2025-04-10T12:41:41.414603",
|
| 533 |
+
"exception": false,
|
| 534 |
+
"start_time": "2025-04-10T12:41:24.831370",
|
| 535 |
+
"status": "completed"
|
| 536 |
+
},
|
| 537 |
+
"scrolled": true,
|
| 538 |
+
"tags": []
|
| 539 |
+
},
|
| 540 |
+
"outputs": [],
|
| 541 |
+
"source": [
|
| 542 |
+
"import cv2 # For image validation\n",
|
| 543 |
+
"import easyocr # For basic OCR (if needed)\n",
|
| 544 |
+
"import numpy as np\n",
|
| 545 |
+
"from PIL import Image # For image loading\n",
|
| 546 |
+
"from google import genai # Google Gemini API\n",
|
| 547 |
+
"from kaggle_secrets import UserSecretsClient # Securely fetch API keys\n",
|
| 548 |
+
"from IPython.display import Markdown # Display Markdown-formatted text\n",
|
| 549 |
+
"import json\n",
|
| 550 |
+
"import re\n",
|
| 551 |
+
"\n",
|
| 552 |
+
"genai.__version__\n",
|
| 553 |
+
"reader = easyocr.Reader(['en'])"
|
| 554 |
+
]
|
| 555 |
+
},
|
| 556 |
+
{
|
| 557 |
+
"cell_type": "markdown",
|
| 558 |
+
"id": "8ad151e0",
|
| 559 |
+
"metadata": {
|
| 560 |
+
"papermill": {
|
| 561 |
+
"duration": 0.035736,
|
| 562 |
+
"end_time": "2025-04-10T12:41:41.487309",
|
| 563 |
+
"exception": false,
|
| 564 |
+
"start_time": "2025-04-10T12:41:41.451573",
|
| 565 |
+
"status": "completed"
|
| 566 |
+
},
|
| 567 |
+
"tags": []
|
| 568 |
+
},
|
| 569 |
+
"source": [
|
| 570 |
+
"## Step 2: Set up your API key\n",
|
| 571 |
+
"\n",
|
| 572 |
+
"To run the following cell, your API key must be stored it in a [Kaggle secret](https://www.kaggle.com/discussions/product-feedback/114053) named `GOOGLE_API_KEY`.\n",
|
| 573 |
+
"\n",
|
| 574 |
+
"If you don't already have an API key, you can grab one from [AI Studio](https://aistudio.google.com/app/apikey). You can find [detailed instructions in the docs](https://ai.google.dev/gemini-api/docs/api-key).\n",
|
| 575 |
+
"\n",
|
| 576 |
+
"To make the key available through Kaggle secrets, choose `Secrets` from the `Add-ons` menu and follow the instructions to add your key or enable it for this notebook."
|
| 577 |
+
]
|
| 578 |
+
},
|
| 579 |
+
{
|
| 580 |
+
"cell_type": "code",
|
| 581 |
+
"execution_count": 4,
|
| 582 |
+
"id": "b67861f2",
|
| 583 |
+
"metadata": {
|
| 584 |
+
"execution": {
|
| 585 |
+
"iopub.execute_input": "2025-04-10T12:41:41.632499Z",
|
| 586 |
+
"iopub.status.busy": "2025-04-10T12:41:41.631925Z",
|
| 587 |
+
"iopub.status.idle": "2025-04-10T12:41:42.089240Z",
|
| 588 |
+
"shell.execute_reply": "2025-04-10T12:41:42.088225Z"
|
| 589 |
+
},
|
| 590 |
+
"papermill": {
|
| 591 |
+
"duration": 0.498242,
|
| 592 |
+
"end_time": "2025-04-10T12:41:42.091038",
|
| 593 |
+
"exception": false,
|
| 594 |
+
"start_time": "2025-04-10T12:41:41.592796",
|
| 595 |
+
"status": "completed"
|
| 596 |
+
},
|
| 597 |
+
"tags": []
|
| 598 |
+
},
|
| 599 |
+
"outputs": [],
|
| 600 |
+
"source": [
|
| 601 |
+
"GOOGLE_API_KEY = UserSecretsClient().get_secret(\"GOOGLE_API_KEY2\")\n",
|
| 602 |
+
"client = genai.Client(api_key=GOOGLE_API_KEY)"
|
| 603 |
+
]
|
| 604 |
+
},
|
| 605 |
+
{
|
| 606 |
+
"cell_type": "markdown",
|
| 607 |
+
"id": "9b0c6ac3",
|
| 608 |
+
"metadata": {
|
| 609 |
+
"papermill": {
|
| 610 |
+
"duration": 0.036583,
|
| 611 |
+
"end_time": "2025-04-10T12:41:42.164665",
|
| 612 |
+
"exception": false,
|
| 613 |
+
"start_time": "2025-04-10T12:41:42.128082",
|
| 614 |
+
"status": "completed"
|
| 615 |
+
},
|
| 616 |
+
"tags": []
|
| 617 |
+
},
|
| 618 |
+
"source": [
|
| 619 |
+
"## Step 3: Write Prompt for gemini-2.0-flash"
|
| 620 |
+
]
|
| 621 |
+
},
|
| 622 |
+
{
|
| 623 |
+
"cell_type": "code",
|
| 624 |
+
"execution_count": 5,
|
| 625 |
+
"id": "fb9f5f05",
|
| 626 |
+
"metadata": {
|
| 627 |
+
"execution": {
|
| 628 |
+
"iopub.execute_input": "2025-04-10T12:41:42.241566Z",
|
| 629 |
+
"iopub.status.busy": "2025-04-10T12:41:42.240797Z",
|
| 630 |
+
"iopub.status.idle": "2025-04-10T12:41:42.246150Z",
|
| 631 |
+
"shell.execute_reply": "2025-04-10T12:41:42.245230Z"
|
| 632 |
+
},
|
| 633 |
+
"papermill": {
|
| 634 |
+
"duration": 0.045459,
|
| 635 |
+
"end_time": "2025-04-10T12:41:42.247885",
|
| 636 |
+
"exception": false,
|
| 637 |
+
"start_time": "2025-04-10T12:41:42.202426",
|
| 638 |
+
"status": "completed"
|
| 639 |
+
},
|
| 640 |
+
"tags": []
|
| 641 |
+
},
|
| 642 |
+
"outputs": [],
|
| 643 |
+
"source": [
|
| 644 |
+
"# Prompt for image-based structured output\n",
|
| 645 |
+
"prompt = \"\"\"\n",
|
| 646 |
+
"You are a medical assistant AI. Extract structured data from this handwritten prescription image.\n",
|
| 647 |
+
"\n",
|
| 648 |
+
"Here are some common medicines there strength and usage\n",
|
| 649 |
+
"Medicine Name\tStrength Example\tUsage\n",
|
| 650 |
+
"Paracetamol\t500mg, 650mg\tPain relief, fever\n",
|
| 651 |
+
"Amoxicillin\t250mg, 500mg\tAntibiotic\n",
|
| 652 |
+
"Azithromycin\t250mg, 500mg\tAntibiotic\n",
|
| 653 |
+
"Ibuprofen\t400mg, 600mg\tPain relief, anti-inflammatory\n",
|
| 654 |
+
"Cefixime\t200mg\tAntibiotic\n",
|
| 655 |
+
"Pantoprazole\t40mg\tAcidity, ulcer prevention\n",
|
| 656 |
+
"Domperidone\t10mg\tAnti-nausea\n",
|
| 657 |
+
"Metformin\t500mg, 1000mg\tDiabetes\n",
|
| 658 |
+
"Amlodipine\t5mg\tBlood pressure\n",
|
| 659 |
+
"Cetirizine\t10mg\tAnti-allergy\n",
|
| 660 |
+
"Ranitidine\t150mg\tAcidity\n",
|
| 661 |
+
"Dolo 650\t650mg\tFever, pain relief\n",
|
| 662 |
+
"Ondansetron\t4mg, 8mg\tAnti-vomiting\n",
|
| 663 |
+
"Levocetirizine\t5mg\tAllergy\n",
|
| 664 |
+
"Losartan\t50mg\tBlood pressure\n",
|
| 665 |
+
"Clavulanic Acid\t125mg (with Amox)\tAntibiotic combo\n",
|
| 666 |
+
"Salbutamol\tInhaler/Syrup\tAsthma\n",
|
| 667 |
+
"\n",
|
| 668 |
+
"Even if handwritten, try your best to extract medicine names, dosage frequency (like 1-0-1), and strength (mg).\n",
|
| 669 |
+
"\n",
|
| 670 |
+
"Focus on extracting:\n",
|
| 671 |
+
"- Patient name\n",
|
| 672 |
+
"- List of medicines prescribed (Paracetamol)\n",
|
| 673 |
+
"- Strength (mg, ml, etc.)\n",
|
| 674 |
+
"- Dosage frequency (e.g., 1-0-1 or twice daily)\n",
|
| 675 |
+
"- Duration\n",
|
| 676 |
+
"- Additional notes\n",
|
| 677 |
+
"\n",
|
| 678 |
+
"Return ONLY this JSON format:\n",
|
| 679 |
+
"{\n",
|
| 680 |
+
" \"patient_name\": \"\",\n",
|
| 681 |
+
" \"medicines\": [\n",
|
| 682 |
+
" {\n",
|
| 683 |
+
" \"name\": \"\",\n",
|
| 684 |
+
" \"strength\": \"\",\n",
|
| 685 |
+
" \"dosage_frequency\": \"\",\n",
|
| 686 |
+
" \"duration\": \"\"\n",
|
| 687 |
+
" }\n",
|
| 688 |
+
" ],\n",
|
| 689 |
+
" \"notes\": \"\"\n",
|
| 690 |
+
"}\n",
|
| 691 |
+
"If any field is missing, return it as null.\n",
|
| 692 |
+
"\"\"\""
|
| 693 |
+
]
|
| 694 |
+
},
|
| 695 |
+
{
|
| 696 |
+
"cell_type": "markdown",
|
| 697 |
+
"id": "202b4348",
|
| 698 |
+
"metadata": {
|
| 699 |
+
"papermill": {
|
| 700 |
+
"duration": 0.036349,
|
| 701 |
+
"end_time": "2025-04-10T12:41:42.321816",
|
| 702 |
+
"exception": false,
|
| 703 |
+
"start_time": "2025-04-10T12:41:42.285467",
|
| 704 |
+
"status": "completed"
|
| 705 |
+
},
|
| 706 |
+
"tags": []
|
| 707 |
+
},
|
| 708 |
+
"source": [
|
| 709 |
+
"## Step 4: Example OCR on an uploaded image "
|
| 710 |
+
]
|
| 711 |
+
},
|
| 712 |
+
{
|
| 713 |
+
"cell_type": "code",
|
| 714 |
+
"execution_count": 6,
|
| 715 |
+
"id": "69aac56b",
|
| 716 |
+
"metadata": {
|
| 717 |
+
"execution": {
|
| 718 |
+
"iopub.execute_input": "2025-04-10T12:41:42.396698Z",
|
| 719 |
+
"iopub.status.busy": "2025-04-10T12:41:42.396369Z",
|
| 720 |
+
"iopub.status.idle": "2025-04-10T12:41:42.435333Z",
|
| 721 |
+
"shell.execute_reply": "2025-04-10T12:41:42.434378Z"
|
| 722 |
+
},
|
| 723 |
+
"papermill": {
|
| 724 |
+
"duration": 0.077791,
|
| 725 |
+
"end_time": "2025-04-10T12:41:42.437051",
|
| 726 |
+
"exception": false,
|
| 727 |
+
"start_time": "2025-04-10T12:41:42.359260",
|
| 728 |
+
"status": "completed"
|
| 729 |
+
},
|
| 730 |
+
"tags": []
|
| 731 |
+
},
|
| 732 |
+
"outputs": [],
|
| 733 |
+
"source": [
|
| 734 |
+
"# Load image\n",
|
| 735 |
+
"image_path = '/kaggle/input/sample-prescriptions/data/103.jpg'\n",
|
| 736 |
+
"image = Image.open(image_path)"
|
| 737 |
+
]
|
| 738 |
+
},
|
| 739 |
+
{
|
| 740 |
+
"cell_type": "code",
|
| 741 |
+
"execution_count": 7,
|
| 742 |
+
"id": "ed1b2825",
|
| 743 |
+
"metadata": {
|
| 744 |
+
"execution": {
|
| 745 |
+
"iopub.execute_input": "2025-04-10T12:41:42.512695Z",
|
| 746 |
+
"iopub.status.busy": "2025-04-10T12:41:42.511923Z",
|
| 747 |
+
"iopub.status.idle": "2025-04-10T12:41:44.240251Z",
|
| 748 |
+
"shell.execute_reply": "2025-04-10T12:41:44.239285Z"
|
| 749 |
+
},
|
| 750 |
+
"papermill": {
|
| 751 |
+
"duration": 1.767306,
|
| 752 |
+
"end_time": "2025-04-10T12:41:44.241756",
|
| 753 |
+
"exception": false,
|
| 754 |
+
"start_time": "2025-04-10T12:41:42.474450",
|
| 755 |
+
"status": "completed"
|
| 756 |
+
},
|
| 757 |
+
"tags": []
|
| 758 |
+
},
|
| 759 |
+
"outputs": [
|
| 760 |
+
{
|
| 761 |
+
"name": "stdout",
|
| 762 |
+
"output_type": "stream",
|
| 763 |
+
"text": [
|
| 764 |
+
"```json\n",
|
| 765 |
+
"{\n",
|
| 766 |
+
" \"patient_name\": \"Greg Stefans\",\n",
|
| 767 |
+
" \"medicines\": [\n",
|
| 768 |
+
" {\n",
|
| 769 |
+
" \"name\": \"Cocaine\",\n",
|
| 770 |
+
" \"strength\": \"SUOU\",\n",
|
| 771 |
+
" \"dosage_frequency\": null,\n",
|
| 772 |
+
" \"duration\": null\n",
|
| 773 |
+
" },\n",
|
| 774 |
+
" {\n",
|
| 775 |
+
" \"name\": \"Ung resorcim comp\",\n",
|
| 776 |
+
" \"strength\": \"3T\",\n",
|
| 777 |
+
" \"dosage_frequency\": null,\n",
|
| 778 |
+
" \"duration\": null\n",
|
| 779 |
+
" }\n",
|
| 780 |
+
" ],\n",
|
| 781 |
+
" \"notes\": \"Apply 3 times a day\"\n",
|
| 782 |
+
"}\n",
|
| 783 |
+
"```\n"
|
| 784 |
+
]
|
| 785 |
+
}
|
| 786 |
+
],
|
| 787 |
+
"source": [
|
| 788 |
+
"# Ask Gemini to understand image\n",
|
| 789 |
+
"def is_valid_image(image_path):\n",
|
| 790 |
+
" try:\n",
|
| 791 |
+
" img = cv2.imread(image_path)\n",
|
| 792 |
+
" return img is not None\n",
|
| 793 |
+
" except Exception as e:\n",
|
| 794 |
+
" print(f\"Failed to load image: {image_path}, error: {e}\")\n",
|
| 795 |
+
" return False\n",
|
| 796 |
+
"\n",
|
| 797 |
+
"# Example OCR on an uploaded image\n",
|
| 798 |
+
"if is_valid_image(image_path):\n",
|
| 799 |
+
" response = client.models.generate_content(\n",
|
| 800 |
+
" model=\"gemini-2.0-flash\",\n",
|
| 801 |
+
" contents=[\n",
|
| 802 |
+
" prompt,\n",
|
| 803 |
+
" image])\n",
|
| 804 |
+
" print(response.text) \n",
|
| 805 |
+
"else:\n",
|
| 806 |
+
" print(f\"Skipping corrupted image: {image_path}\")"
|
| 807 |
+
]
|
| 808 |
+
},
|
| 809 |
+
{
|
| 810 |
+
"cell_type": "markdown",
|
| 811 |
+
"id": "5f8bf9db",
|
| 812 |
+
"metadata": {
|
| 813 |
+
"papermill": {
|
| 814 |
+
"duration": 0.03661,
|
| 815 |
+
"end_time": "2025-04-10T12:41:44.315470",
|
| 816 |
+
"exception": false,
|
| 817 |
+
"start_time": "2025-04-10T12:41:44.278860",
|
| 818 |
+
"status": "completed"
|
| 819 |
+
},
|
| 820 |
+
"tags": []
|
| 821 |
+
},
|
| 822 |
+
"source": [
|
| 823 |
+
"## Step 5: Trying out Chat Model"
|
| 824 |
+
]
|
| 825 |
+
},
|
| 826 |
+
{
|
| 827 |
+
"cell_type": "code",
|
| 828 |
+
"execution_count": 8,
|
| 829 |
+
"id": "fd770528",
|
| 830 |
+
"metadata": {
|
| 831 |
+
"execution": {
|
| 832 |
+
"iopub.execute_input": "2025-04-10T12:41:44.391332Z",
|
| 833 |
+
"iopub.status.busy": "2025-04-10T12:41:44.390927Z",
|
| 834 |
+
"iopub.status.idle": "2025-04-10T12:41:45.896031Z",
|
| 835 |
+
"shell.execute_reply": "2025-04-10T12:41:45.895171Z"
|
| 836 |
+
},
|
| 837 |
+
"papermill": {
|
| 838 |
+
"duration": 1.545711,
|
| 839 |
+
"end_time": "2025-04-10T12:41:45.897584",
|
| 840 |
+
"exception": false,
|
| 841 |
+
"start_time": "2025-04-10T12:41:44.351873",
|
| 842 |
+
"status": "completed"
|
| 843 |
+
},
|
| 844 |
+
"tags": []
|
| 845 |
+
},
|
| 846 |
+
"outputs": [
|
| 847 |
+
{
|
| 848 |
+
"data": {
|
| 849 |
+
"text/markdown": [
|
| 850 |
+
"Okay!\n",
|
| 851 |
+
"\n",
|
| 852 |
+
"* **Azithromycin** is an antibiotic. It's used to treat a variety of bacterial infections, such as respiratory infections (like bronchitis or pneumonia), skin infections, and sexually transmitted infections.\n",
|
| 853 |
+
"\n",
|
| 854 |
+
"* **Cetirizine** is an antihistamine. It's commonly used to relieve allergy symptoms such as runny nose, sneezing, itchy eyes, and skin rashes.\n",
|
| 855 |
+
"\n",
|
| 856 |
+
"So, it sounds like you may have a bacterial infection and are experiencing allergy symptoms.\n",
|
| 857 |
+
"\n",
|
| 858 |
+
"Please consult a licensed medical professional before taking any medication.\n"
|
| 859 |
+
],
|
| 860 |
+
"text/plain": [
|
| 861 |
+
"<IPython.core.display.Markdown object>"
|
| 862 |
+
]
|
| 863 |
+
},
|
| 864 |
+
"execution_count": 8,
|
| 865 |
+
"metadata": {},
|
| 866 |
+
"output_type": "execute_result"
|
| 867 |
+
}
|
| 868 |
+
],
|
| 869 |
+
"source": [
|
| 870 |
+
"# Load Gemini Chat Model\n",
|
| 871 |
+
"chat = client.chats.create(model=\"gemini-2.0-flash\")\n",
|
| 872 |
+
"\n",
|
| 873 |
+
"# Define few-shot prompt to guide the agent\n",
|
| 874 |
+
"system_prompt = \"\"\"\n",
|
| 875 |
+
"You are a friendly and knowledgeable AI medical assistant named MediSync.\n",
|
| 876 |
+
"You help patients understand their prescriptions, medications, and basic symptoms.\n",
|
| 877 |
+
"\n",
|
| 878 |
+
"Example Q&A:\n",
|
| 879 |
+
"\n",
|
| 880 |
+
"Q: I was prescribed Paracetamol 650mg. What is it for?\n",
|
| 881 |
+
"A: Paracetamol is used to relieve fever and mild to moderate pain, such as headaches or body aches.\n",
|
| 882 |
+
"\n",
|
| 883 |
+
"Q: My prescription has Amoxicillin and Clavulanic acid. What condition could this be?\n",
|
| 884 |
+
"A: That combination is often used to treat bacterial infections like sinusitis, throat infections, or bronchitis.\n",
|
| 885 |
+
"\n",
|
| 886 |
+
"Q: What medicine should I take for acidity?\n",
|
| 887 |
+
"A: Over-the-counter medicines like Pantoprazole or Ranitidine are commonly used for acidity. Please consult a doctor before taking any medication.\n",
|
| 888 |
+
"\n",
|
| 889 |
+
"Always include a disclaimer like: \"Please consult a licensed medical professional before taking any medication.\"\n",
|
| 890 |
+
"\n",
|
| 891 |
+
"Start interacting now.\n",
|
| 892 |
+
"\"\"\"\n",
|
| 893 |
+
"\n",
|
| 894 |
+
"# Send system prompt to chat session\n",
|
| 895 |
+
"chat.send_message(system_prompt)\n",
|
| 896 |
+
"\n",
|
| 897 |
+
"# Example chat interaction\n",
|
| 898 |
+
"user_question = \"I was prescribed Azithromycin and Cetirizine. What are they used for?\"\n",
|
| 899 |
+
"response = chat.send_message(user_question)\n",
|
| 900 |
+
"\n",
|
| 901 |
+
"Markdown(response.text)\n"
|
| 902 |
+
]
|
| 903 |
+
},
|
| 904 |
+
{
|
| 905 |
+
"cell_type": "markdown",
|
| 906 |
+
"id": "53ddb8ca",
|
| 907 |
+
"metadata": {
|
| 908 |
+
"papermill": {
|
| 909 |
+
"duration": 0.037569,
|
| 910 |
+
"end_time": "2025-04-10T12:41:45.972235",
|
| 911 |
+
"exception": false,
|
| 912 |
+
"start_time": "2025-04-10T12:41:45.934666",
|
| 913 |
+
"status": "completed"
|
| 914 |
+
},
|
| 915 |
+
"tags": []
|
| 916 |
+
},
|
| 917 |
+
"source": [
|
| 918 |
+
"## Step 6: Building Gradio Interface"
|
| 919 |
+
]
|
| 920 |
+
},
|
| 921 |
+
{
|
| 922 |
+
"cell_type": "code",
|
| 923 |
+
"execution_count": 9,
|
| 924 |
+
"id": "f7136439",
|
| 925 |
+
"metadata": {
|
| 926 |
+
"execution": {
|
| 927 |
+
"iopub.execute_input": "2025-04-10T12:41:46.053703Z",
|
| 928 |
+
"iopub.status.busy": "2025-04-10T12:41:46.053388Z",
|
| 929 |
+
"iopub.status.idle": "2025-04-10T12:41:51.808620Z",
|
| 930 |
+
"shell.execute_reply": "2025-04-10T12:41:51.807705Z"
|
| 931 |
+
},
|
| 932 |
+
"papermill": {
|
| 933 |
+
"duration": 5.798177,
|
| 934 |
+
"end_time": "2025-04-10T12:41:51.810261",
|
| 935 |
+
"exception": false,
|
| 936 |
+
"start_time": "2025-04-10T12:41:46.012084",
|
| 937 |
+
"status": "completed"
|
| 938 |
+
},
|
| 939 |
+
"tags": []
|
| 940 |
+
},
|
| 941 |
+
"outputs": [
|
| 942 |
+
{
|
| 943 |
+
"name": "stderr",
|
| 944 |
+
"output_type": "stream",
|
| 945 |
+
"text": [
|
| 946 |
+
"/tmp/ipykernel_13/1192573786.py:72: UserWarning: You have not specified a value for the `type` parameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style dictionaries with 'role' and 'content' keys.\n",
|
| 947 |
+
" chatbot=gr.Chatbot(label=\"MediSync\"),\n",
|
| 948 |
+
"/usr/local/lib/python3.11/dist-packages/gradio/blocks.py:1115: UserWarning: Cannot load compact. Caught Exception: 404 Client Error: Not Found for url: https://huggingface.co/api/spaces/compact (Request ID: Root=1-67f7bc8d-299c34a7360aed6e6d6ab95b;708ae4ba-5fb8-4ce9-941b-4dbf872a2ed8)\n",
|
| 949 |
+
"\n",
|
| 950 |
+
"Sorry, we can't find the page you are looking for.\n",
|
| 951 |
+
" warnings.warn(f\"Cannot load {theme}. Caught Exception: {str(e)}\")\n",
|
| 952 |
+
"/usr/local/lib/python3.11/dist-packages/gradio/chat_interface.py:314: UserWarning: The type of the gr.Chatbot does not match the type of the gr.ChatInterface.The type of the gr.ChatInterface, 'messages', will be used.\n",
|
| 953 |
+
" warnings.warn(\n"
|
| 954 |
+
]
|
| 955 |
+
},
|
| 956 |
+
{
|
| 957 |
+
"name": "stdout",
|
| 958 |
+
"output_type": "stream",
|
| 959 |
+
"text": [
|
| 960 |
+
"* Running on local URL: http://127.0.0.1:7860\n",
|
| 961 |
+
"Kaggle notebooks require sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
| 962 |
+
"\n",
|
| 963 |
+
"* Running on public URL: https://35c21101bf8d390fde.gradio.live\n",
|
| 964 |
+
"\n",
|
| 965 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"
|
| 966 |
+
]
|
| 967 |
+
},
|
| 968 |
+
{
|
| 969 |
+
"data": {
|
| 970 |
+
"text/html": [
|
| 971 |
+
"<div><iframe src=\"https://35c21101bf8d390fde.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 972 |
+
],
|
| 973 |
+
"text/plain": [
|
| 974 |
+
"<IPython.core.display.HTML object>"
|
| 975 |
+
]
|
| 976 |
+
},
|
| 977 |
+
"metadata": {},
|
| 978 |
+
"output_type": "display_data"
|
| 979 |
+
},
|
| 980 |
+
{
|
| 981 |
+
"data": {
|
| 982 |
+
"text/plain": []
|
| 983 |
+
},
|
| 984 |
+
"execution_count": 9,
|
| 985 |
+
"metadata": {},
|
| 986 |
+
"output_type": "execute_result"
|
| 987 |
+
}
|
| 988 |
+
],
|
| 989 |
+
"source": [
|
| 990 |
+
"import gradio as gr\n",
|
| 991 |
+
"from PIL import Image\n",
|
| 992 |
+
"from google import genai\n",
|
| 993 |
+
"\n",
|
| 994 |
+
"# Function to handle image input\n",
|
| 995 |
+
"def extract_prescription(image):\n",
|
| 996 |
+
" if image is None:\n",
|
| 997 |
+
" return \"Please upload an image.\"\n",
|
| 998 |
+
"\n",
|
| 999 |
+
" response = client.models.generate_content(\n",
|
| 1000 |
+
" model=\"gemini-2.0-flash\",\n",
|
| 1001 |
+
" contents=[\n",
|
| 1002 |
+
" prompt,\n",
|
| 1003 |
+
" image\n",
|
| 1004 |
+
" ]\n",
|
| 1005 |
+
" )\n",
|
| 1006 |
+
" text = response.text.strip()\n",
|
| 1007 |
+
"\n",
|
| 1008 |
+
" # Remove markdown formatting if any\n",
|
| 1009 |
+
" if text.startswith(\"```json\"):\n",
|
| 1010 |
+
" text = re.sub(r\"```json|```\", \"\", text).strip()\n",
|
| 1011 |
+
"\n",
|
| 1012 |
+
" try:\n",
|
| 1013 |
+
" data = json.loads(text)\n",
|
| 1014 |
+
"\n",
|
| 1015 |
+
" # Format nicely\n",
|
| 1016 |
+
" output = f\"### 👩⚕️ Prescription Summary\\n\"\n",
|
| 1017 |
+
" output += f\"- **Patient Name:** {data.get('patient_name', 'N/A') or 'N/A'}\\n\"\n",
|
| 1018 |
+
" output += f\"- **Medicines Prescribed:**\\n\"\n",
|
| 1019 |
+
"\n",
|
| 1020 |
+
" for med in data.get(\"medicines\", []):\n",
|
| 1021 |
+
" name = med.get(\"name\") or \"Unknown\"\n",
|
| 1022 |
+
" strength = med.get(\"strength\") or \"N/A\"\n",
|
| 1023 |
+
" freq = med.get(\"dosage_frequency\") or \"N/A\"\n",
|
| 1024 |
+
" duration = med.get(\"duration\") or \"N/A\"\n",
|
| 1025 |
+
" output += f\" - 💊 **{name}** – {strength} – Dosage: {freq} – Duration: {duration}\\n\"\n",
|
| 1026 |
+
"\n",
|
| 1027 |
+
" notes = data.get(\"notes\") or \"None\"\n",
|
| 1028 |
+
" output += f\"- **Notes:** {notes}\\n\"\n",
|
| 1029 |
+
"\n",
|
| 1030 |
+
" return output\n",
|
| 1031 |
+
"\n",
|
| 1032 |
+
" except Exception as e:\n",
|
| 1033 |
+
" return f\"❌ Error parsing response:\\n{text}\"\n",
|
| 1034 |
+
"\n",
|
| 1035 |
+
"\n",
|
| 1036 |
+
"# Chatbot function\n",
|
| 1037 |
+
"def chat_with_medisync(user_question, history):\n",
|
| 1038 |
+
" try:\n",
|
| 1039 |
+
" response = chat.send_message(user_question)\n",
|
| 1040 |
+
" return response.text\n",
|
| 1041 |
+
" except Exception as e:\n",
|
| 1042 |
+
" return f\"❌ Error: {e}\"\n",
|
| 1043 |
+
"\n",
|
| 1044 |
+
"# Gradio Interface\n",
|
| 1045 |
+
"with gr.Blocks() as MediSyncAI:\n",
|
| 1046 |
+
" gr.Markdown(\"## 🧠 MediSync.AI - Prescription Reader + Chatbot\")\n",
|
| 1047 |
+
"\n",
|
| 1048 |
+
" with gr.Tab(\"📸 Upload Prescription\"):\n",
|
| 1049 |
+
" with gr.Row():\n",
|
| 1050 |
+
" image_input = gr.Image(type=\"pil\", label=\"Upload Prescription Image\")\n",
|
| 1051 |
+
" json_output = gr.Markdown(label=\"Prescription Summary\")\n",
|
| 1052 |
+
"\n",
|
| 1053 |
+
" extract_btn = gr.Button(\"Extract Info\")\n",
|
| 1054 |
+
" extract_btn.click(fn=extract_prescription, inputs=image_input, outputs=json_output)\n",
|
| 1055 |
+
"\n",
|
| 1056 |
+
" with gr.Tab(\"💬 Chat with MediSync\"):\n",
|
| 1057 |
+
" chatbot = gr.ChatInterface(\n",
|
| 1058 |
+
" fn=chat_with_medisync,\n",
|
| 1059 |
+
" type=\"messages\",\n",
|
| 1060 |
+
" title=\"MediSync-AI Chatbot\",\n",
|
| 1061 |
+
" chatbot=gr.Chatbot(label=\"MediSync\"),\n",
|
| 1062 |
+
" textbox=gr.Textbox(placeholder=\"Type your medical question here...\", label=\"Your question\"),\n",
|
| 1063 |
+
" theme=\"compact\",\n",
|
| 1064 |
+
" )\n",
|
| 1065 |
+
"\n",
|
| 1066 |
+
"MediSyncAI.launch()\n"
|
| 1067 |
+
]
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"cell_type": "code",
|
| 1071 |
+
"execution_count": null,
|
| 1072 |
+
"id": "8e301983",
|
| 1073 |
+
"metadata": {
|
| 1074 |
+
"papermill": {
|
| 1075 |
+
"duration": 0.037968,
|
| 1076 |
+
"end_time": "2025-04-10T12:41:51.886595",
|
| 1077 |
+
"exception": false,
|
| 1078 |
+
"start_time": "2025-04-10T12:41:51.848627",
|
| 1079 |
+
"status": "completed"
|
| 1080 |
+
},
|
| 1081 |
+
"tags": []
|
| 1082 |
+
},
|
| 1083 |
+
"outputs": [],
|
| 1084 |
+
"source": []
|
| 1085 |
+
}
|
| 1086 |
+
],
|
| 1087 |
+
"metadata": {
|
| 1088 |
+
"kaggle": {
|
| 1089 |
+
"accelerator": "none",
|
| 1090 |
+
"dataSources": [
|
| 1091 |
+
{
|
| 1092 |
+
"datasetId": 7102462,
|
| 1093 |
+
"sourceId": 11350664,
|
| 1094 |
+
"sourceType": "datasetVersion"
|
| 1095 |
+
}
|
| 1096 |
+
],
|
| 1097 |
+
"dockerImageVersionId": 31012,
|
| 1098 |
+
"isGpuEnabled": false,
|
| 1099 |
+
"isInternetEnabled": true,
|
| 1100 |
+
"language": "python",
|
| 1101 |
+
"sourceType": "notebook"
|
| 1102 |
+
},
|
| 1103 |
+
"kernelspec": {
|
| 1104 |
+
"display_name": "Python 3",
|
| 1105 |
+
"language": "python",
|
| 1106 |
+
"name": "python3"
|
| 1107 |
+
},
|
| 1108 |
+
"language_info": {
|
| 1109 |
+
"codemirror_mode": {
|
| 1110 |
+
"name": "ipython",
|
| 1111 |
+
"version": 3
|
| 1112 |
+
},
|
| 1113 |
+
"file_extension": ".py",
|
| 1114 |
+
"mimetype": "text/x-python",
|
| 1115 |
+
"name": "python",
|
| 1116 |
+
"nbconvert_exporter": "python",
|
| 1117 |
+
"pygments_lexer": "ipython3",
|
| 1118 |
+
"version": "3.11.11"
|
| 1119 |
+
},
|
| 1120 |
+
"papermill": {
|
| 1121 |
+
"default_parameters": {},
|
| 1122 |
+
"duration": 140.358489,
|
| 1123 |
+
"end_time": "2025-04-10T12:41:54.546120",
|
| 1124 |
+
"environment_variables": {},
|
| 1125 |
+
"exception": null,
|
| 1126 |
+
"input_path": "__notebook__.ipynb",
|
| 1127 |
+
"output_path": "__notebook__.ipynb",
|
| 1128 |
+
"parameters": {},
|
| 1129 |
+
"start_time": "2025-04-10T12:39:34.187631",
|
| 1130 |
+
"version": "2.6.0"
|
| 1131 |
+
}
|
| 1132 |
+
},
|
| 1133 |
+
"nbformat": 4,
|
| 1134 |
+
"nbformat_minor": 5
|
| 1135 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiofiles==24.1.0
|
| 2 |
+
annotated-types==0.7.0
|
| 3 |
+
anyio==4.9.0
|
| 4 |
+
audioop-lts==0.2.1
|
| 5 |
+
cachetools==5.5.2
|
| 6 |
+
certifi==2025.1.31
|
| 7 |
+
charset-normalizer==3.4.1
|
| 8 |
+
click==8.1.8
|
| 9 |
+
fastapi==0.115.12
|
| 10 |
+
ffmpy==0.5.0
|
| 11 |
+
filelock==3.18.0
|
| 12 |
+
fsspec==2025.3.2
|
| 13 |
+
google-ai-generativelanguage==0.6.15
|
| 14 |
+
google-api-core==2.24.2
|
| 15 |
+
google-api-python-client==2.166.0
|
| 16 |
+
google-auth==2.38.0
|
| 17 |
+
google-auth-httplib2==0.2.0
|
| 18 |
+
google-generativeai==0.8.4
|
| 19 |
+
googleapis-common-protos==1.69.2
|
| 20 |
+
gradio==5.25.0
|
| 21 |
+
gradio_client==1.8.0
|
| 22 |
+
groovy==0.1.2
|
| 23 |
+
grpcio==1.72.0rc1
|
| 24 |
+
grpcio-status==1.71.0
|
| 25 |
+
h11==0.14.0
|
| 26 |
+
httpcore==1.0.8
|
| 27 |
+
httplib2==0.22.0
|
| 28 |
+
httpx==0.28.1
|
| 29 |
+
huggingface-hub==0.30.2
|
| 30 |
+
idna==3.10
|
| 31 |
+
Jinja2==3.1.6
|
| 32 |
+
markdown-it-py==3.0.0
|
| 33 |
+
MarkupSafe==3.0.2
|
| 34 |
+
mdurl==0.1.2
|
| 35 |
+
numpy==2.2.4
|
| 36 |
+
orjson==3.10.16
|
| 37 |
+
packaging==24.2
|
| 38 |
+
pandas==2.2.3
|
| 39 |
+
pillow==11.1.0
|
| 40 |
+
proto-plus==1.26.1
|
| 41 |
+
protobuf==5.29.4
|
| 42 |
+
pyasn1==0.6.1
|
| 43 |
+
pyasn1_modules==0.4.2
|
| 44 |
+
pydantic==2.11.3
|
| 45 |
+
pydantic_core==2.33.1
|
| 46 |
+
pydub==0.25.1
|
| 47 |
+
Pygments==2.19.1
|
| 48 |
+
pyparsing==3.2.3
|
| 49 |
+
python-dateutil==2.9.0.post0
|
| 50 |
+
python-dotenv==1.1.0
|
| 51 |
+
python-multipart==0.0.20
|
| 52 |
+
pytz==2025.2
|
| 53 |
+
PyYAML==6.0.2
|
| 54 |
+
requests==2.32.3
|
| 55 |
+
rich==14.0.0
|
| 56 |
+
rsa==4.9
|
| 57 |
+
ruff==0.11.5
|
| 58 |
+
safehttpx==0.1.6
|
| 59 |
+
semantic-version==2.10.0
|
| 60 |
+
shellingham==1.5.4
|
| 61 |
+
six==1.17.0
|
| 62 |
+
sniffio==1.3.1
|
| 63 |
+
starlette==0.46.1
|
| 64 |
+
tomlkit==0.13.2
|
| 65 |
+
tqdm==4.67.1
|
| 66 |
+
typer==0.15.2
|
| 67 |
+
typing-inspection==0.4.0
|
| 68 |
+
typing_extensions==4.13.2
|
| 69 |
+
tzdata==2025.2
|
| 70 |
+
uritemplate==4.1.1
|
| 71 |
+
urllib3==2.4.0
|
| 72 |
+
uvicorn==0.34.0
|
| 73 |
+
websockets==15.0.1
|