├── Final ChatBot.ipynb ├── README.md └── lab_assistant.db /Final ChatBot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 3, 6 | "id": "e7293244-3e3b-485a-963e-fd7472217f05", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "name": "stdout", 11 | "output_type": "stream", 12 | "text": [ 13 | "Database and tables created successfully.\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "import sqlite3\n", 19 | "\n", 20 | "\n", 21 | "conn = sqlite3.connect('lab_assistant.db')\n", 22 | "\n", 23 | "\n", 24 | "def create_tables():\n", 25 | " cursor = conn.cursor()\n", 26 | " \n", 27 | "\n", 28 | " cursor.execute(\"DROP TABLE IF EXISTS reminders\")\n", 29 | " \n", 30 | "\n", 31 | " cursor.execute('''\n", 32 | " CREATE TABLE IF NOT EXISTS reminders (\n", 33 | " id INTEGER PRIMARY KEY AUTOINCREMENT,\n", 34 | " reminder TEXT NOT NULL,\n", 35 | " due_date TEXT NOT NULL,\n", 36 | " due_time TEXT NOT NULL,\n", 37 | " status TEXT DEFAULT 'Pending'\n", 38 | " )\n", 39 | " ''')\n", 40 | "\n", 41 | " cursor.execute(\"DROP TABLE IF EXISTS inventory\")\n", 42 | "\n", 43 | " cursor.execute('''\n", 44 | " CREATE TABLE IF NOT EXISTS inventory (\n", 45 | " id INTEGER PRIMARY KEY AUTOINCREMENT,\n", 46 | " item TEXT NOT NULL,\n", 47 | " quantity INTEGER NOT NULL,\n", 48 | " expiry_date TEXT NOT NULL\n", 49 | " )\n", 50 | " ''')\n", 51 | "\n", 52 | " conn.commit()\n", 53 | " conn.close()\n", 54 | "\n", 55 | "create_tables()\n", 56 | "print(\"Database and tables created successfully.\")\n" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 5, 62 | "id": "29aa1db7-ea44-440a-993a-6877b56915c1", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "Running on local URL: http://127.0.0.1:7860\n", 70 | "\n", 71 | "Thanks for being a Gradio user! If you have questions or feedback, please join our Discord server and chat with us: https://discord.gg/feTf9x3ZSB\n", 72 | "Running on public URL: https://df8e454cc0ad439421.gradio.live\n", 73 | "\n", 74 | "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n" 75 | ] 76 | }, 77 | { 78 | "data": { 79 | "text/html": [ 80 | "
" 81 | ], 82 | "text/plain": [ 83 | "" 84 | ] 85 | }, 86 | "metadata": {}, 87 | "output_type": "display_data" 88 | }, 89 | { 90 | "data": { 91 | "text/plain": [] 92 | }, 93 | "execution_count": 5, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "import gradio as gr\n", 100 | "import sqlite3\n", 101 | "import google.generativeai as gemini\n", 102 | "import threading\n", 103 | "import time\n", 104 | "import datetime\n", 105 | "import tkinter as tk\n", 106 | "from tkinter import messagebox\n", 107 | "\n", 108 | "gemini.configure(api_key=\"your api key\") \n", 109 | "model = gemini.GenerativeModel('gemini-pro')\n", 110 | "\n", 111 | "\n", 112 | "def connect_db():\n", 113 | " conn = sqlite3.connect('lab_assistant.db')\n", 114 | " return conn\n", 115 | "\n", 116 | "def check_reminders():\n", 117 | " while True:\n", 118 | " now = datetime.datetime.now()\n", 119 | " current_time = now.strftime(\"%Y-%m-%d %H:%M\")\n", 120 | " conn = connect_db()\n", 121 | " cursor = conn.cursor()\n", 122 | " cursor.execute(\"SELECT reminder FROM reminders WHERE due_date = ? AND due_time = ? AND status = 'Pending'\", \n", 123 | " (now.strftime(\"%Y-%m-%d\"), now.strftime(\"%H:%M\")))\n", 124 | " reminders = cursor.fetchall()\n", 125 | " conn.close()\n", 126 | " \n", 127 | " for reminder in reminders:\n", 128 | " show_popup(reminder[0])\n", 129 | " mark_reminder_as_done(reminder[0])\n", 130 | " time.sleep(60) \n", 131 | "\n", 132 | "def show_popup(reminder):\n", 133 | " root = tk.Tk()\n", 134 | " root.withdraw() \n", 135 | " messagebox.showinfo(\"Reminder\", reminder)\n", 136 | " root.destroy()\n", 137 | "\n", 138 | "\n", 139 | "def mark_reminder_as_done(reminder):\n", 140 | " conn = connect_db()\n", 141 | " cursor = conn.cursor()\n", 142 | " cursor.execute(\"UPDATE reminders SET status = 'Done' WHERE reminder = ?\", (reminder,))\n", 143 | " conn.commit()\n", 144 | " conn.close()\n", 145 | "\n", 146 | "\n", 147 | "conversation_history=[]\n", 148 | "def ask_biotech_query(query):\n", 149 | " global conversation_history\n", 150 | " context = \" \".join(conversation_history[-3:]) \n", 151 | " full_query = f\"{context} {query}\"\n", 152 | "\n", 153 | " try:\n", 154 | " response = model.generate_content(full_query)\n", 155 | " conversation_history.append(f\"Q: {query}\\nA: {response.text}\")\n", 156 | " return response.text, conversation_history \n", 157 | " except Exception as e:\n", 158 | " return f\"Error: {str(e)}\", conversation_history\n", 159 | "\n", 160 | "\n", 161 | "def display_reminders():\n", 162 | " conn = connect_db()\n", 163 | " cursor = conn.cursor()\n", 164 | " cursor.execute(\"SELECT * FROM reminders\")\n", 165 | " reminders = cursor.fetchall()\n", 166 | " conn.close()\n", 167 | " return \"\\n\".join([f\"{r[1]} (Due: {r[2]} at {r[3]}, Status: {r[4]})\" for r in reminders]) if reminders else \"No reminders.\"\n", 168 | "\n", 169 | "\n", 170 | "def display_inventory():\n", 171 | " conn = connect_db()\n", 172 | " cursor = conn.cursor()\n", 173 | " cursor.execute(\"SELECT * FROM inventory\")\n", 174 | " inventory = cursor.fetchall()\n", 175 | " conn.close()\n", 176 | " return \"\\n\".join([f\"{i[1]} (Quantity: {i[2]}, Expiry: {i[3]})\" for i in inventory]) if inventory else \"No inventory items.\"\n", 177 | "\n", 178 | "\n", 179 | "def add_reminder(reminder, due_date, due_time, status=\"Pending\"):\n", 180 | " conn = connect_db()\n", 181 | " cursor = conn.cursor()\n", 182 | " cursor.execute(\"INSERT INTO reminders (reminder, due_date, due_time, status) VALUES (?, ?, ?, ?)\", \n", 183 | " (reminder, due_date, due_time, status))\n", 184 | " conn.commit()\n", 185 | " conn.close()\n", 186 | " return \"Reminder added!\"\n", 187 | "\n", 188 | "\n", 189 | "def update_inventory(item, quantity, expiry_date):\n", 190 | " conn = connect_db()\n", 191 | " cursor = conn.cursor()\n", 192 | " cursor.execute(\"INSERT INTO inventory (item, quantity, expiry_date) VALUES (?, ?, ?)\", \n", 193 | " (item, quantity, expiry_date))\n", 194 | " conn.commit()\n", 195 | " conn.close()\n", 196 | " return \"Inventory updated!\"\n", 197 | "\n", 198 | "reminder_thread = threading.Thread(target=check_reminders, daemon=True)\n", 199 | "reminder_thread.start()\n", 200 | "\n", 201 | "\n", 202 | "with gr.Blocks() as app:\n", 203 | " gr.Markdown(\"# 🧬 Smart Biotech Lab Assistant\")\n", 204 | "\n", 205 | "\n", 206 | " gr.Markdown(\"### 🔔 Manage Reminders\")\n", 207 | " with gr.Row():\n", 208 | " reminder_display_btn = gr.Button(\"View All Reminders\")\n", 209 | " reminder_output = gr.Textbox(label=\"Reminders\", interactive=False)\n", 210 | " reminder_display_btn.click(display_reminders, outputs=reminder_output)\n", 211 | "\n", 212 | " reminder_input = gr.Textbox(label=\"Add Reminder\")\n", 213 | " due_date_input = gr.Textbox(label=\"Due Date (YYYY-MM-DD)\")\n", 214 | " due_time_input = gr.Textbox(label=\"Due Time (HH:MM, 24-hour format)\")\n", 215 | " reminder_add_btn = gr.Button(\"Add Reminder\")\n", 216 | " reminder_add_output = gr.Textbox(label=\"Reminder Status\", interactive=False)\n", 217 | " reminder_add_btn.click(add_reminder, inputs=[reminder_input, due_date_input, due_time_input], outputs=reminder_add_output)\n", 218 | "\n", 219 | "\n", 220 | " gr.Markdown(\"### 📦 Manage Inventory\")\n", 221 | " with gr.Row():\n", 222 | " inventory_display_btn = gr.Button(\"View All Inventory\")\n", 223 | " inventory_output = gr.Textbox(label=\"Inventory\", interactive=False)\n", 224 | " inventory_display_btn.click(display_inventory, outputs=inventory_output)\n", 225 | "\n", 226 | " item_input = gr.Textbox(label=\"Add Item\")\n", 227 | " quantity_input = gr.Textbox(label=\"Quantity\")\n", 228 | " expiry_input = gr.Textbox(label=\"Expiry Date (YYYY-MM-DD or No expiry)\")\n", 229 | " inventory_add_btn = gr.Button(\"Update Inventory\")\n", 230 | " inventory_add_output = gr.Textbox(label=\"Inventory Status\", interactive=False)\n", 231 | " inventory_add_btn.click(update_inventory, inputs=[item_input, quantity_input, expiry_input], outputs=inventory_add_output)\n", 232 | "\n", 233 | " gr.Markdown(\"### 🧑‍🔬 Ask Biotech Questions\")\n", 234 | " query_input = gr.Textbox(label=\"Ask a Biotech Question\")\n", 235 | " query_btn = gr.Button(\"Get Answer\")\n", 236 | " query_output = gr.Textbox(label=\"Answer\", interactive=False)\n", 237 | " history_output = gr.Textbox(label=\"Conversation History\", interactive=False)\n", 238 | "\n", 239 | " query_btn.click(ask_biotech_query, inputs=query_input, outputs=[query_output, history_output])\n", 240 | "\n", 241 | "app.launch(share=True)\n" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": null, 247 | "id": "8a18284e-0a0f-47ea-9e26-76f05262b296", 248 | "metadata": {}, 249 | "outputs": [], 250 | "source": [] 251 | } 252 | ], 253 | "metadata": { 254 | "kernelspec": { 255 | "display_name": "Python 3 (ipykernel)", 256 | "language": "python", 257 | "name": "python3" 258 | }, 259 | "language_info": { 260 | "codemirror_mode": { 261 | "name": "ipython", 262 | "version": 3 263 | }, 264 | "file_extension": ".py", 265 | "mimetype": "text/x-python", 266 | "name": "python", 267 | "nbconvert_exporter": "python", 268 | "pygments_lexer": "ipython3", 269 | "version": "3.12.4" 270 | } 271 | }, 272 | "nbformat": 4, 273 | "nbformat_minor": 5 274 | } 275 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Smart Biotech Lab Assistant 3 | 4 | **Smart Biotech Lab Assistant** is an AI chatbot designed to assist biotech researchers with everyday lab tasks. The assistant helps in setting reminders for experiments, tracking lab inventory, and answering common biotech-related questions. It is built using **Python** and designed to be run in a **Jupyter Notebook**. 5 | 6 | ## Team 7 | 8 | We are a team of four members: 9 | - **Abishek Khanna** (myself) 10 | - **Yuvaraj** 11 | - **Amuthan** 12 | - **Roobis** 13 | 14 | We collaboratively developed this tool to enhance lab efficiency and reduce administrative burdens in biotech research environments. 15 | 16 | ## Features 17 | 18 | - **Set Experiment Reminders**: Schedule and track time-sensitive experiments. 19 | - **Lab Inventory Management**: Monitor and manage chemicals, reagents, and consumables in real-time. 20 | - **Biotech Knowledge Base**: Answer common biotech-related questions with information on protocols, chemical properties, and safety measures. 21 | - **Adaptive Suggestions**: Provides quantity ranges for chemicals and tips on optimizing lab results based on experimental context. 22 | - **User Feedback Loop**: Collects user feedback post-experiment to refine future suggestions. 23 | 24 | ## Installation 25 | 26 | 1. **Clone the repository**: 27 | 28 | ```bash 29 | git clone https://github.com/Abishekkhanna/Lab-Assistant-ChatBot.git 30 | ``` 31 | 32 | 2. **Navigate to the project directory**: 33 | 34 | ```bash 35 | cd Lab-Assistant-ChatBot 36 | ``` 37 | 38 | 3. **Run the Jupyter Notebook**: 39 | 40 | Make sure Jupyter Notebook is installed. You can run the application by launching the notebook: 41 | 42 | ```bash 43 | jupyter Final ChatBot.ipynb 44 | ``` 45 | 46 | 4. **Interact with the Application**: 47 | 48 | Follow the cells in the Jupyter Notebook to interact with the chatbot using Gradio. 49 | 50 | ## Usage 51 | 52 | 1. Interact with the AI chatbot by asking biotech-related questions, such as setting reminders, checking inventory, or asking for protocol steps. 53 | 2. Provide feedback after an experiment to improve future suggestions. 54 | 55 | ## Requirements 56 | 57 | - Python 3.7+ 58 | - Jupyter Notebook 59 | - Gradio 60 | 61 | ## Contributing 62 | 63 | Feel free to fork this repository and submit pull requests. For significant changes, please open an issue first to discuss what you would like to change. 64 | 65 | -------------------------------------------------------------------------------- /lab_assistant.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abishekkhanna/Lab-Assistant-ChatBot/423d4b166ba8ada37d66c7cd78ea9a1dda70783b/lab_assistant.db --------------------------------------------------------------------------------