...
Browse files
README.md
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: MediBot
|
3 |
+
emoji: 🏥
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: green
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: "1.38.0"
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
# MediBot - Health Assistant
|
13 |
+
|
14 |
+
MediBot is a Streamlit-based web application designed to assist users in identifying possible health conditions based on symptoms and answering health-related questions using AI. It leverages a Neon PostgreSQL database for storing user data and symptom-disease mappings, and integrates with the Groq API for natural language responses.
|
15 |
+
|
16 |
+
**Disclaimer**: This app provides preliminary health information based on symptoms and AI analysis. It is not a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare provider for any health concerns.
|
17 |
+
|
18 |
+
## Features
|
19 |
+
- **Symptom-Based Diagnosis**: Users can select symptoms to receive potential disease matches, descriptions, and precautions based on provided datasets.
|
20 |
+
- **Health Question Answering**: Users can ask free-text health questions, answered via the Groq API.
|
21 |
+
- **User Management**: Optional registration and login to save symptom history, with a unique user ID.
|
22 |
+
- **History Tracking**: Registered users can view their past symptom searches and AI responses.
|
23 |
+
- **Database Integration**: Uses Neon PostgreSQL to store user data, symptoms, diseases, and history.
|
24 |
+
- **Responsive Design**: Built with Streamlit for a user-friendly interface.
|
25 |
+
|
26 |
+
## Setup Instructions
|
27 |
+
|
28 |
+
### Prerequisites
|
29 |
+
- A Hugging Face account to deploy the Space.
|
30 |
+
- A Neon PostgreSQL database with the schema set up (see `create_tables.sql`).
|
31 |
+
- A Groq API key for answering health questions.
|
32 |
+
|
33 |
+
### Deployment on Hugging Face
|
34 |
+
1. **Create a New Space**:
|
35 |
+
- Go to [Hugging Face Spaces](https://huggingface.co/spaces) and create a new Space.
|
36 |
+
- Choose the Streamlit SDK and name your Space (e.g., `MediBot`).
|
37 |
+
|
38 |
+
2. **Upload Files**:
|
39 |
+
- Upload the following files to the Space repository:
|
40 |
+
- `app.py`
|
41 |
+
- `database.py`
|
42 |
+
- `user_management.py`
|
43 |
+
- `requirements.txt`
|
44 |
+
- `create_tables.sql` (for reference)
|
45 |
+
- `README.md` (this file)
|
46 |
+
|
47 |
+
3. **Configure Secrets**:
|
48 |
+
- In the Space settings, add the following secrets:
|
49 |
+
- `DB_CONNECT`: Your Neon PostgreSQL connection string (e.g., `postgresql://neondb_owner:mypassword@ep-shiny-band-a2wzybro-pooler.eu-central-1.aws.neon.tech/medibot?sslmode=require&channel_binding=require`).
|
50 |
+
- `GROQ_API_KEY`: Your Groq API key.
|
51 |
+
|
52 |
+
4. **Set Up Database**:
|
53 |
+
- Connect to your Neon PostgreSQL database using a tool like `psql` or Neon's SQL editor.
|
54 |
+
- Run the SQL script in `create_tables.sql` to create and populate the tables (`mb_users`, `mb_history`, `mb_symptoms`, `mb_diseases`, `mb_disease_symptoms`).
|
55 |
+
|
56 |
+
5. **Deploy**:
|
57 |
+
- Commit the files and wait for Hugging Face to build and deploy the Space.
|
58 |
+
- Once deployed, access the app via the provided Space URL.
|
59 |
+
|
60 |
+
### Local Development
|
61 |
+
1. **Clone the Repository**:
|
62 |
+
```bash
|
63 |
+
git clone https://huggingface.co/spaces/<your-username>/MediBot
|
64 |
+
cd MediBot
|
65 |
+
```
|
66 |
+
|
67 |
+
2. **Install Dependencies**:
|
68 |
+
```bash
|
69 |
+
pip install -r requirements.txt
|
70 |
+
```
|
71 |
+
|
72 |
+
3. **Set Environment Variables**:
|
73 |
+
```bash
|
74 |
+
export DB_CONNECT="postgresql://neondb_owner:mypassword@ep-shiny-band-a2wzybro-pooler.eu-central-1.aws.neon.tech/medibot?sslmode=require&channel_binding=require"
|
75 |
+
export GROQ_API_KEY="your-groq-api-key"
|
76 |
+
```
|
77 |
+
|
78 |
+
4. **Run the App**:
|
79 |
+
```bash
|
80 |
+
streamlit run app.py
|
81 |
+
```
|
82 |
+
|
83 |
+
5. **Access the App**:
|
84 |
+
- Open your browser and navigate to `http://localhost:8501`.
|
85 |
+
|
86 |
+
## Project Structure
|
87 |
+
- `app.py`: Main Streamlit app handling symptom input, diagnosis, and health question queries.
|
88 |
+
- `database.py`: Manages database connections and queries for symptoms, diseases, and user history.
|
89 |
+
- `user_management.py`: Handles user registration, login, and history display.
|
90 |
+
- `create_tables.sql`: SQL script to set up the Neon PostgreSQL database.
|
91 |
+
- `requirements.txt`: Python dependencies for the app.
|
92 |
+
|
93 |
+
## Database Schema
|
94 |
+
- **mb_users**: Stores user information (user_id, date_of_birth, email, registration_date).
|
95 |
+
- **mb_history**: Stores user symptom history and predicted diseases.
|
96 |
+
- **mb_symptoms**: Stores symptom names and severity weights.
|
97 |
+
- **mb_diseases**: Stores disease names, descriptions, and precautions.
|
98 |
+
- **mb_disease_symptoms**: Maps diseases to symptoms for diagnosis.
|
99 |
+
|
100 |
+
## Datasets
|
101 |
+
The app uses the following datasets (populated in the database via `create_tables.sql`):
|
102 |
+
- `dataset.csv`: Maps symptoms to diseases.
|
103 |
+
- `Symptom-severity.csv`: Provides symptom weights.
|
104 |
+
- `symptom_Description.csv`: Disease descriptions.
|
105 |
+
- `symptom_precaution.csv`: Disease precautions.
|
106 |
+
|
107 |
+
## Technologies Used
|
108 |
+
- **Streamlit**: For the web interface.
|
109 |
+
- **Neon PostgreSQL**: For data storage.
|
110 |
+
- **Groq API**: For answering health questions.
|
111 |
+
- **psycopg2**: For PostgreSQL database connectivity.
|
112 |
+
- **Python**: Core programming language.
|
113 |
+
|
114 |
+
## Contributing
|
115 |
+
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
|
116 |
+
|
117 |
+
## License
|
118 |
+
This project is licensed under the MIT License.
|
119 |
+
|
120 |
+
## Contact
|
121 |
+
For support or inquiries, contact the xAI team or open an issue in the repository.
|
122 |
+
|
123 |
+
---
|
124 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|