Muhammadtaha12 commited on
Commit
d37fea4
·
verified ·
1 Parent(s): 3a27d27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -38
app.py CHANGED
@@ -1,4 +1,9 @@
 
1
  import streamlit as st
 
 
 
 
2
 
3
  # Disease and Treatment Information Data
4
  diseases_info = {
@@ -22,14 +27,18 @@ diseases_info = {
22
  "symptoms": ["shortness of breath", "wheezing", "chest tightness", "coughing"],
23
  "treatment": "Inhalers, bronchodilators, corticosteroids, and avoiding triggers.",
24
  },
25
- "pneumonia": {
26
- "symptoms": ["cough with mucus", "fever", "shortness of breath", "chest pain"],
27
- "treatment": "Antibiotics for bacterial pneumonia, rest, fluids, and pain relievers.",
28
- },
29
  "hypertension": {
30
  "symptoms": ["headaches", "dizziness", "shortness of breath", "nosebleeds"],
31
  "treatment": "Medications like beta-blockers, ACE inhibitors, lifestyle changes including exercise and diet.",
32
  },
 
 
 
 
 
 
 
 
33
  "anxiety": {
34
  "symptoms": ["excessive worry", "restlessness", "fatigue", "difficulty concentrating", "irritability"],
35
  "treatment": "Cognitive-behavioral therapy (CBT), medications like SSRIs, relaxation techniques.",
@@ -38,70 +47,68 @@ diseases_info = {
38
  "symptoms": ["persistent sadness", "loss of interest", "fatigue", "changes in appetite or sleep patterns"],
39
  "treatment": "Antidepressants, therapy (CBT), exercise, and social support.",
40
  },
41
- "arthritis": {
42
- "symptoms": ["joint pain", "swelling", "stiffness", "reduced range of motion"],
43
- "treatment": "Pain relievers, anti-inflammatory drugs, physical therapy, and joint protection.",
44
- },
45
- "covid-19": {
46
- "symptoms": ["fever", "dry cough", "fatigue", "loss of taste or smell", "shortness of breath"],
47
- "treatment": "Rest, fluids, over-the-counter medications, and antiviral drugs if prescribed.",
48
  },
49
- "blood cancer": {
50
- "symptoms": ["weightloss", "hiarfall", "weakness", "bedrest"],
51
- "treatment": " over-the-counter medications, and antiviral drugs if prescribed.",
52
  },
53
  }
54
 
55
-
56
  # Function to display disease info
57
  def display_disease_info(disease_name):
58
  disease_name = disease_name.lower().replace(" ", "_")
59
  if disease_name in diseases_info:
60
  disease = diseases_info[disease_name]
61
- result = f"\n**Disease:** {disease_name.replace('_', ' ').title()}"
62
- result += f"\n**Symptoms:** {', '.join(disease['symptoms'])}"
63
- result += f"\n**Treatment:** {disease['treatment']}"
64
  return result
65
  else:
66
- return "\nSorry, no information available for this disease."
67
 
68
- # Function to handle the chat bot
69
  def chat_bot(user_input):
70
- if 'cha hal aa' in user_input.lower():
71
- if 'are you healthcare app' in user_input.lower():
72
- return "na rai mazak na kar maa app"
73
- return "Khair aa, tu budha!"
74
- elif 'exit' in user_input.lower():
75
- return "Goodbye!"
76
- else:
77
- return "I'm not sure how to respond to that. Type 'exit' to end the chat."
78
 
79
  # Streamlit App Interface
80
  def main():
81
  # Title of the app
82
- st.title("Disease Information and Chat Bot")
83
-
84
  # Disease Input
85
  disease_name = st.text_input("Enter Disease Name", "")
86
  if disease_name:
87
  st.subheader("Disease Information")
88
  disease_info = display_disease_info(disease_name)
89
  st.text_area("Disease Info", disease_info, height=150)
90
-
91
  # Chat Bot Section
92
  st.subheader("Chat with Bot")
93
- user_input = st.text_input("Enter a Message (e.g., How are you?)", "")
94
  if user_input:
95
  response = chat_bot(user_input)
96
  st.text_area("Chat Bot Response", response, height=100)
97
-
98
- # Add some helpful instructions
99
- st.markdown("""
 
100
  - **Enter a disease name** in the input box to get information about symptoms and treatments.
101
- - **Ask the chat bot** something like "How are you?" to interact with it.
102
- - Type "exit" to end the chat session.
103
- """)
104
 
105
  # Run the app
106
  if __name__ == "__main__":
107
  main()
 
 
1
+ import os
2
  import streamlit as st
3
+ from groq import Groq
4
+ GROQ_API_KEY = "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"
5
+ # Initialize Groq Client
6
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
7
 
8
  # Disease and Treatment Information Data
9
  diseases_info = {
 
27
  "symptoms": ["shortness of breath", "wheezing", "chest tightness", "coughing"],
28
  "treatment": "Inhalers, bronchodilators, corticosteroids, and avoiding triggers.",
29
  },
 
 
 
 
30
  "hypertension": {
31
  "symptoms": ["headaches", "dizziness", "shortness of breath", "nosebleeds"],
32
  "treatment": "Medications like beta-blockers, ACE inhibitors, lifestyle changes including exercise and diet.",
33
  },
34
+ "arthritis": {
35
+ "symptoms": ["joint pain", "swelling", "stiffness", "reduced range of motion"],
36
+ "treatment": "Pain relievers, anti-inflammatory drugs, physical therapy, and joint protection.",
37
+ },
38
+ "covid-19": {
39
+ "symptoms": ["fever", "dry cough", "fatigue", "loss of taste or smell", "shortness of breath"],
40
+ "treatment": "Rest, fluids, over-the-counter medications, and antiviral drugs if prescribed.",
41
+ },
42
  "anxiety": {
43
  "symptoms": ["excessive worry", "restlessness", "fatigue", "difficulty concentrating", "irritability"],
44
  "treatment": "Cognitive-behavioral therapy (CBT), medications like SSRIs, relaxation techniques.",
 
47
  "symptoms": ["persistent sadness", "loss of interest", "fatigue", "changes in appetite or sleep patterns"],
48
  "treatment": "Antidepressants, therapy (CBT), exercise, and social support.",
49
  },
50
+ # Additional Diseases
51
+ "migraine": {
52
+ "symptoms": ["severe headache", "nausea", "sensitivity to light and sound"],
53
+ "treatment": "Prescription medications, rest in a dark room, and lifestyle adjustments.",
 
 
 
54
  },
55
+ "eczema": {
56
+ "symptoms": ["itchy skin", "red rashes", "dry skin", "cracked or scaly patches"],
57
+ "treatment": "Moisturizers, corticosteroid creams, antihistamines, and avoiding irritants.",
58
  },
59
  }
60
 
 
61
  # Function to display disease info
62
  def display_disease_info(disease_name):
63
  disease_name = disease_name.lower().replace(" ", "_")
64
  if disease_name in diseases_info:
65
  disease = diseases_info[disease_name]
66
+ result = f"**Disease:** {disease_name.replace('_', ' ').title()}\n"
67
+ result += f"**Symptoms:** {', '.join(disease['symptoms'])}\n"
68
+ result += f"**Treatment:** {disease['treatment']}"
69
  return result
70
  else:
71
+ return "Sorry, no information available for this disease."
72
 
73
+ # Function to interact with Groq API for Chat Bot
74
  def chat_bot(user_input):
75
+ try:
76
+ chat_completion = client.chat.completions.create(
77
+ messages=[{"role": "user", "content": user_input}],
78
+ model="llama-3.3-70b-versatile",
79
+ )
80
+ return chat_completion.choices[0].message.content
81
+ except Exception as e:
82
+ return f"Error: Unable to process your request. {str(e)}"
83
 
84
  # Streamlit App Interface
85
  def main():
86
  # Title of the app
87
+ st.title("Health Guide Chat Bot")
88
+
89
  # Disease Input
90
  disease_name = st.text_input("Enter Disease Name", "")
91
  if disease_name:
92
  st.subheader("Disease Information")
93
  disease_info = display_disease_info(disease_name)
94
  st.text_area("Disease Info", disease_info, height=150)
95
+
96
  # Chat Bot Section
97
  st.subheader("Chat with Bot")
98
+ user_input = st.text_input("Enter a Message for the Chat Bot", "")
99
  if user_input:
100
  response = chat_bot(user_input)
101
  st.text_area("Chat Bot Response", response, height=100)
102
+
103
+ # Add instructions
104
+ st.markdown(
105
+ """
106
  - **Enter a disease name** in the input box to get information about symptoms and treatments.
107
+ - **Chat with the bot** to get general health advice or answers to your questions.
108
+ """
109
+ )
110
 
111
  # Run the app
112
  if __name__ == "__main__":
113
  main()
114
+