Skip to content

rashadmin/medai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MedAI

A conversational AI assistant for first aid guidance and medical information extraction, powered by Google Gemini and Flask.

🧠 Overview

MedAI is a Flask-based web application designed to provide immediate, intelligent first aid guidance and extract structured medical information from user conversations. It serves as a helpful assistant for both anonymous and registered users, offering a conversational interface and integrating with the YouTube API for relevant video resources.

🔨 What I Built

This project delivers a multi-faceted AI assistant with the following core features:

  • Conversational First Aid Guidance: An AI agent powered by Google Gemini provides interactive first aid advice based on user input.
  • Structured Medical Information Extraction: The AI can extract key medical details from conversations and present them in a structured format.
  • User Management: Supports both anonymous and registered user accounts, allowing for personalized chat histories.
  • Secure API Endpoints: A comprehensive set of RESTful API endpoints for managing users, chats, and authentication tokens, secured with token-based and basic HTTP authentication.
  • Dynamic Video Resources: Integrates with the YouTube Data API to fetch short, relevant first aid videos based on conversational context.
  • Robust Configuration: Utilizes environment variables for secure and flexible application configuration, including API keys and database connections.

💭 Thought Process

My approach focused on building a modular and extensible Flask application. I leveraged the Flask application factory pattern and blueprints to organize the codebase into logical, manageable units for API, chat, and video functionalities. This decision facilitates maintainability and allows for easier addition of new features.

For the conversational AI, I chose Google Gemini due to its powerful generative capabilities. A key design decision was to implement distinct AI interaction classes: one for general chat and another for structured information extraction. This allows for precise prompting strategies tailored to each task, ensuring the AI performs optimally for both free-form conversation and data parsing. Careful consideration was given to Gemini's safety settings to allow for appropriate medical content while maintaining responsible AI usage.

Database design revolved around SQLAlchemy, defining User, Anonyuser, and Conversation models to effectively manage different user types and their chat histories. I incorporated Flask-Login and Flask-HTTPAuth to implement robust authentication, ensuring secure access control for registered users while also accommodating anonymous interactions.

Finally, integrating the YouTube API was a crucial step to provide tangible, visual first aid resources. I designed the video search function to be specific, targeting short, embeddable videos relevant to medical first aid scenarios, thereby enhancing the practical utility of the application.

🛠️ Tools & Tech Stack

Layer Technology
Language Python 3.x
Web Framework Flask
Database ORM Flask-SQLAlchemy, SQLAlchemy
Migrations Flask-Migrate
AI / LLM Google Gemini (via google.generativeai)
External APIs YouTube Data API v3 (requests)
Authentication Flask-Login, Flask-HTTPAuth, Werkzeug
Configuration python-dotenv
Utilities uuid, dateutil, datetime, enum, logging, json, secrets, os

🚀 Getting Started

Prerequisites

  • Python >= 3.x
  • A Google Gemini API key
  • A YouTube Data API v3 key
  • A PostgreSQL database (or other SQLAlchemy-compatible database)

Installation

git clone https://github.com/rashadmin/medai.git
cd medai
pip install -r requirements.txt

Environment Variables

Create a .env file in the root directory:

SECRET_KEY=your_flask_secret_key
DATABASE_URL=postgresql://user:password@host:port/database_name
GEMINI_API_KEY=your_gemini_api_key
YOUTUBE_API_KEY=your_youtube_api_key

Run

flask db upgrade # Apply database migrations
flask run

Or, for development with the Flask shell:

flask shell

📖 Usage

Example 1: Creating an Anonymous User and Chat

curl -X POST http://127.0.0.1:5000/api/anonyuser \
     -H "Content-Type: application/json" \
     -d '{"gender": "male", "age_class": "adult", "blood_group": "A+", "genotype": "AA"}'
{
  "anony_user_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
  "blood_group": "A+",
  "gender": "male",
  "genotype": "AA",
  "id": 1
}

Then, using the anony_user_id to start a chat:

curl -X POST http://127.0.0.1:5000/api/anonyuser/a1b2c3d4-e5f6-7890-1234-567890abcdef/chat \
     -H "Content-Type: application/json" \
     -d '{"message": "I cut my finger, what should I do?"}'
{
  "assistant_message": "Clean the wound with soap and water, apply direct pressure, and cover it with a sterile bandage.",
  "conversation_no": 1,
  "human_message": "I cut my finger, what should I do?",
  "timestamp": "..."
}

Example 2: Structured Information Extraction (via internal logic)

The AI can extract structured information from complex prompts. For instance, if a user describes symptoms, the AI might identify key medical details. This is primarily handled internally within the Conversation model's logic.

📚 Resources

📄 License

MIT © rashadmin

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors