aminahmed78 commited on
Commit
5b3c8c9
·
verified ·
1 Parent(s): 9b5ad74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +151 -0
app.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from groq import Groq
4
+ import os
5
+
6
+ # --------------------------
7
+ # 1. Dataset Setup (Updated with Urdu)
8
+ # --------------------------
9
+ data = {
10
+ "symptoms_en": ["headache", "fever", "insomnia", "anxiety", "cough"],
11
+ "symptoms_es": ["dolor de cabeza", "fiebre", "insomnio", "ansiedad", "tos"],
12
+ "symptoms_hi": ["सिरदर्द", "बुखार", "अनिद्रा", "चिंता", "खांसी"],
13
+ "symptoms_ur": ["سر درد", "بخار", "بے خوابی", "اضطراب", "کھانسی"],
14
+ "remedy": ["Belladonna", "Aconitum", "Coffea", "Argentum nitricum", "Drosera"],
15
+ "potency": ["30C"]*5,
16
+ "usage": ["3 times daily"]*5
17
+ }
18
+
19
+ df = pd.DataFrame(data)
20
+
21
+ # --------------------------
22
+ # 2. Groq Setup (Multilingual Processing)
23
+ # --------------------------
24
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
25
+
26
+ def analyze_symptoms(text, language):
27
+ """Use Groq's Llama 3 for symptom analysis"""
28
+ lang_map = {
29
+ 'en': 'English',
30
+ 'es': 'Spanish',
31
+ 'hi': 'Hindi',
32
+ 'ur': 'Urdu'
33
+ }
34
+
35
+ prompt = f"""Task: Extract medical symptoms from this {lang_map[language]} text.
36
+ Text: {text}
37
+ Output format: Comma-separated symptoms in {lang_map[language]}.
38
+ Example: headache, muscle pain, dry cough"""
39
+
40
+ try:
41
+ chat_completion = client.chat.completions.create(
42
+ messages=[{"role": "user", "content": prompt}],
43
+ model="llama3-70b-8192",
44
+ temperature=0.1
45
+ )
46
+ return [s.strip() for s in chat_completion.choices[0].message.content.split(",")]
47
+ except Exception as e:
48
+ st.error(f"Error in Groq API: {str(e)}")
49
+ return []
50
+
51
+ # --------------------------
52
+ # 3. Streamlit UI (Multilingual Interface)
53
+ # --------------------------
54
+ st.set_page_config(page_title="Homeo Doctor", page_icon="🌿")
55
+
56
+ # Language selection
57
+ language = st.sidebar.selectbox("भाषा चुनें/Select Language",
58
+ ['English', 'Español', 'हिन्दी', 'اردو'],
59
+ format_func=lambda x: x)
60
+
61
+ lang_code = {
62
+ 'English': 'en',
63
+ 'Español': 'es',
64
+ 'हिन्दी': 'hi',
65
+ 'اردو': 'ur'
66
+ }[language]
67
+
68
+ # Header with dynamic language
69
+ headers = {
70
+ 'en': "🌿 Homeopathic Doctor",
71
+ 'es': "🌿 Doctor Homeopático",
72
+ 'hi': "🌿 होम्योपैथिक डॉक्टर",
73
+ 'ur': "🌿 ہومیوپیتھک ڈاکٹر"
74
+ }
75
+ st.header(headers[lang_code])
76
+
77
+ # MCQ Symptoms
78
+ symptom_col = f"symptoms_{lang_code}"
79
+ symptoms = df[symptom_col].tolist()
80
+ selected = st.multiselect(
81
+ label={
82
+ 'en': "Select your symptoms:",
83
+ 'es': "Seleccione sus síntomas:",
84
+ 'hi': "अपने लक्षण चुनें:",
85
+ 'ur': "اپنی علامات منتخب کریں:"
86
+ }[lang_code],
87
+ options=symptoms
88
+ )
89
+
90
+ # Chat Input
91
+ chat_input = st.text_input(
92
+ label={
93
+ 'en': "Describe other symptoms:",
94
+ 'es': "Describa otros síntomas:",
95
+ 'hi': "अन्य लक्षण बताएं:",
96
+ 'ur': "دیگر علامات بیان کریں:"
97
+ }[lang_code],
98
+ placeholder={
99
+ 'en': "Type symptoms not listed above...",
100
+ 'ur': "اوپر درج نہ کی گئی علامات ٹائپ کریں..."
101
+ }[lang_code] if lang_code == 'ur' else ""
102
+ )
103
+
104
+ # Diagnosis Logic
105
+ if st.button({
106
+ 'en': "Get Recommendation",
107
+ 'es': "Obtener Recomendación",
108
+ 'hi': "सिफारिश प्राप्त करें",
109
+ 'ur': "تجویز حاصل کریں"
110
+ }[lang_code]):
111
+ # Process chat input
112
+ if chat_input:
113
+ analyzed_symptoms = analyze_symptoms(chat_input, lang_code)
114
+ selected += [s for s in analyzed_symptoms if s in symptoms]
115
+
116
+ # Find best remedy
117
+ if not selected:
118
+ st.warning({
119
+ 'en': "Please select or describe symptoms!",
120
+ 'ur': "براہ کرم علامات منتخب کریں یا بیان کریں!"
121
+ }[lang_code] if lang_code == 'ur' else "")
122
+ else:
123
+ matches = df[df[symptom_col].isin(selected)]
124
+ if not matches.empty:
125
+ remedy = matches.iloc[0]
126
+ st.success(f"""
127
+ **{remedy['remedy']}**
128
+ {{
129
+ 'en': "Potency: {remedy['potency']}",
130
+ 'ur': "طاقت: {remedy['potency']}"
131
+ }}[lang_code]
132
+ {{
133
+ 'en': "Usage: {remedy['usage']}",
134
+ 'ur': "استعمال: {remedy['usage']}"
135
+ }}[lang_code]
136
+ """)
137
+ else:
138
+ st.error({
139
+ 'en': "No matching remedy found. Consult a professional.",
140
+ 'ur': "کوئی مماثل دوا نہیں ملی۔ پیشہ ور سے مشورہ کریں۔"
141
+ }[lang_code])
142
+
143
+ # Disclaimer
144
+ st.markdown("""
145
+ ---
146
+ **⚠️ Notice/نوٹس:**
147
+ This is not medical advice. Always consult a qualified homeopath.
148
+ यह चिकित्सीय सलाह नहीं है। हमेशा योग्य होम्योपैथ से सलाह लें۔
149
+ Esto no es un consejo médico. Siempre consulte a un homeópata calificado.
150
+ یہ طبی مشورہ نہیں ہے۔ ہمیشہ کوالیفائڈ ہومیوپیتھک ڈاکٹر سے مشورہ کریں۔
151
+ """)