Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Define the healthcare knowledge base or fetch from APIs
|
| 5 |
+
health_knowledge_base = {
|
| 6 |
+
"flu": {
|
| 7 |
+
"symptoms": ["fever", "cough", "sore throat", "body aches", "fatigue"],
|
| 8 |
+
"treatment": "Rest, fluids, pain relievers, and anti-viral medications if prescribed.",
|
| 9 |
+
},
|
| 10 |
+
"headache": {
|
| 11 |
+
"symptoms": ["head pain", "nausea", "sensitivity to light"],
|
| 12 |
+
"treatment": "Rest, hydration, over-the-counter painkillers, and avoid triggers.",
|
| 13 |
+
},
|
| 14 |
+
"diabetes": {
|
| 15 |
+
"symptoms": ["increased thirst", "frequent urination", "fatigue", "blurred vision"],
|
| 16 |
+
"treatment": "Insulin therapy, lifestyle changes, and dietary management.",
|
| 17 |
+
},
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# Function to search for health information in the knowledge base
|
| 21 |
+
def get_health_info(query):
|
| 22 |
+
query = query.lower()
|
| 23 |
+
|
| 24 |
+
# Search for conditions that match the query
|
| 25 |
+
for condition, info in health_knowledge_base.items():
|
| 26 |
+
if condition in query:
|
| 27 |
+
return f"Condition: {condition.title()}\n" \
|
| 28 |
+
f"Symptoms: {', '.join(info['symptoms'])}\n" \
|
| 29 |
+
f"Treatment: {info['treatment']}"
|
| 30 |
+
|
| 31 |
+
return "Sorry, I couldn't find information on that condition. Please try another query."
|
| 32 |
+
|
| 33 |
+
# Set up the Streamlit app interface
|
| 34 |
+
st.title("Healthcare Knowledge Chatbot")
|
| 35 |
+
st.write("Ask me about health conditions, symptoms, treatments, and I'll provide relevant information.")
|
| 36 |
+
|
| 37 |
+
# Input field for user queries
|
| 38 |
+
user_input = st.text_input("Ask a healthcare-related question...")
|
| 39 |
+
|
| 40 |
+
# Display response based on user input
|
| 41 |
+
if user_input:
|
| 42 |
+
response = get_health_info(user_input)
|
| 43 |
+
st.write(response)
|