Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Initialize the Groq API client using the environment variable for the API key
|
| 10 |
+
client = Groq(
|
| 11 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Function to handle health-related queries
|
| 15 |
+
def get_health_advice(query):
|
| 16 |
+
health_issues = ['fever', 'flu', 'cough', 'malaria', 'tb', 'allergy', 'lazy', 'typhoid']
|
| 17 |
+
if any(issue in query.lower() for issue in health_issues):
|
| 18 |
+
# Send query to Groq API to get response
|
| 19 |
+
response = client.query(query)
|
| 20 |
+
return response.get('answer', 'Sorry, I could not find a solution for your query.')
|
| 21 |
+
else:
|
| 22 |
+
return "Sorry, I do not have knowledge of this topic. Please ask me only health-related questions."
|
| 23 |
+
|
| 24 |
+
# Streamlit UI
|
| 25 |
+
st.title("Health Assistant Chatbot")
|
| 26 |
+
st.write("Ask me about any health issues, and I will try to help you with proper advice and treatment.")
|
| 27 |
+
|
| 28 |
+
# User input for the query
|
| 29 |
+
user_input = st.text_input("Describe your symptoms or ask about your health issue:")
|
| 30 |
+
|
| 31 |
+
if user_input:
|
| 32 |
+
response = get_health_advice(user_input)
|
| 33 |
+
st.write("Response:", response)
|