Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from groq import Groq
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load environment variables from the .env file
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Fetch the API key from the environment variable
|
| 10 |
+
api_key = os.getenv("GROQ_API_KEY")
|
| 11 |
+
|
| 12 |
+
# Ensure the API key is set
|
| 13 |
+
if not api_key:
|
| 14 |
+
st.error("API key not found. Please make sure the GROQ_API_KEY is set in your .env file.")
|
| 15 |
+
else:
|
| 16 |
+
client = Groq(api_key=api_key)
|
| 17 |
+
|
| 18 |
+
# Function to call the Groq API and get the chatbot response
|
| 19 |
+
def get_chat_response(query):
|
| 20 |
+
chat_completion = client.chat.completions.create(
|
| 21 |
+
messages=[{"role": "user", "content": query}],
|
| 22 |
+
model="llama-3.3-70b-versatile",
|
| 23 |
+
)
|
| 24 |
+
return chat_completion.choices[0].message.content
|
| 25 |
+
|
| 26 |
+
# Streamlit app interface
|
| 27 |
+
def main():
|
| 28 |
+
st.title("Health Assistant Chatbot")
|
| 29 |
+
|
| 30 |
+
# Provide health-related options for users
|
| 31 |
+
st.write("Please ask a health-related question. The chatbot can answer questions about fever, flu, cough, malaria, and typhoid symptoms.")
|
| 32 |
+
|
| 33 |
+
# Input from the user
|
| 34 |
+
user_input = st.text_input("Ask a health-related question:")
|
| 35 |
+
|
| 36 |
+
if user_input:
|
| 37 |
+
# Check if the question is health-related
|
| 38 |
+
health_keywords = ["fever", "flu", "cough", "malaria", "typhoid"]
|
| 39 |
+
if any(keyword in user_input.lower() for keyword in health_keywords):
|
| 40 |
+
response = get_chat_response(user_input)
|
| 41 |
+
st.write("Chatbot Response:", response)
|
| 42 |
+
else:
|
| 43 |
+
st.write("Sorry, I do not have knowledge of this topic. Please ask only health-related questions.")
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
main()
|