diff --git a/cometllm.py b/cometllm.py index edbe588..64877d6 100644 --- a/cometllm.py +++ b/cometllm.py @@ -3,18 +3,22 @@ import streamlit as st import comet_llm from openai import OpenAI +from dotenv import load_dotenv -#used the medical chatbot AI advice list from an article on Medium, CometML and OpenAI (turbo-3.5) APIs but I keep getting 429 error code +load dotenv() +OPENAI_API_KEY = os.getenv("OPENAI_KEY") +COMET_API_KEY = os.getenv("COMET_API_KEY") + +#used the medical chatbot AI advice list from an article on Medium, CometML and OpenAI (turbo-3.5) APIs st.title("AI-Powered Healthcare Chatbot") st.write("Ask any medical question, our AI doctor is here to help!") -comet_llm.init( - api_key=os.getenv("API_KEY"), - project="Doc_bot_openai" -) +# Initialize CometML +comet_llm.init(api_key=COMET_API_KEY, project="Doc_bot_openai") -client = OpenAI(api_key=os.getenv("OPENAI_KEY")) +# Initialize OpenAI Client +client = OpenAI(api_key=OPENAI_API_KEY) advice_list = ''' # Medical Advice List diff --git a/medicalchatbot.py b/medicalchatbot.py new file mode 100644 index 0000000..1d8f18d --- /dev/null +++ b/medicalchatbot.py @@ -0,0 +1,101 @@ +import os +import time +import streamlit as st +import comet_llm +from openai import OpenAI +from dotenv import load_dotenv + +load_dotenv() +OPENAI_API_KEY = os.getenv("OPENAI_KEY") +COMET_API_KEY = os.getenv("COMET_API_KEY") + +#used the medical chatbot AI advice list from an article on Medium, CometML and OpenAI (turbo-3.5) APIs + +st.title("AI-Powered Healthcare Chatbot") +st.write("Ask any medical question, our AI doctor is here to help!") + +# Initialize CometML +comet_llm.init(api_key=COMET_API_KEY, project="Doc_bot_openai") + +# Initialize OpenAI Client +client = OpenAI(api_key=OPENAI_API_KEY) + +advice_list = ''' +# Medical Advice List + +## General Health: +- Healthy Diet: Include a variety of fruits and vegetables in your diet. +- Regular Exercise: Aim for at least 30 minutes of moderate exercise most days of the week. +- Adequate Sleep: Ensure you get 7-9 hours of sleep per night for overall well-being. + +## Common Ailments: +- Cold and Flu Remedies: Stay hydrated, get plenty of rest, and consider over-the-counter cold remedies. +- Headache Relief: Drink water, rest in a quiet room, and consider pain relievers. + +## Emergency Situations: +- First Aid for Burns: Run cold water over the burn, cover with a clean cloth, and seek medical attention. +- CPR Guidelines: Call for help, start chest compressions, and follow emergency protocols. +''' + +context_doctor = [ + {'role': 'system', 'content': f""" + You are DoctorBot, an AI assistant providing medical advice. + + Be empathetic and informative in your responses. + + The Current Medical Advice List: + ```{advice_list}``` + """} +] + +if "messages" not in st.session_state: + st.session_state.messages = [] + +def format_message(role, content): + if role == "user": + return f'