Spaces:
Sleeping
Sleeping
File size: 9,968 Bytes
f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 3fdc359 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 f0144dd 5b3c8c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# app.py
import streamlit as st
from groq import Groq
import os
import requests
from bs4 import BeautifulSoup
import re
from urllib.parse import quote_plus
# Groq API setup
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
# Web scraping functions
def google_search(query):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
encoded_query = quote_plus(query)
url = f"https://www.google.com/search?q={encoded_query}&gl=us&hl=en"
try:
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
results = []
for g in soup.find_all('div', class_='tF2Cxc'):
link = g.find('a')['href']
title = g.find('h3').text
snippet = g.find('div', class_='VwiC3b')
if snippet:
results.append({
'title': title,
'link': link,
'snippet': snippet.text
})
return results[:3] # Return top 3 results
except Exception as e:
st.error(f"سرچ ایرر: {str(e)}")
return []
# Homeopathic dosage extraction (Urdu supported)
def extract_dosage_info(text):
patterns = [
r'(\d+[\s-]*\d*\s*(بار|قطرے|گولیاں|خوارج)\s*(فی دن|روزانہ))',
r'(دن میں \d+\s*بار)',
r'(\d+-\d+\s*گھنٹے کے وقفے سے)'
]
for pattern in patterns:
match = re.search(pattern, text)
if match:
return match.group()
return "دن میں 3 بار (ڈیفالٹ)"
# Chatbot logic
def homeo_chatbot_urdu(user_input):
# Step 1: Symptom extraction in Urdu
symptom_prompt = f"""صارف کی تفصیل: {user_input}
ہومیوپیتھک علامات کو انگلش میں کاما سے علیحدہ فہرست میں نکالیں۔
مثال: headache, dry cough, fever with chills"""
try:
symptom_response = client.chat.completions.create(
messages=[{"role": "user", "content": symptom_prompt}],
model="llama3-70b-8192",
temperature=0.2
)
symptoms = symptom_response.choices[0].message.content.split(", ")
except Exception as e:
return f"ایرر: {str(e)}"
# Step 2: Web search for remedies
search_query = f"homeopathic remedies for {' '.join(symptoms)} site:.edu OR site:.gov"
search_results = google_search(search_query)
remedies = []
for result in search_results:
remedies.append({
'title': result['title'],
'link': result['link'],
'content': result['snippet']
})
# Step 3: Prepare response in Urdu
final_response = "🌿 **تجویز کردہ ہومیوپیتھک علاج:**\n\n"
for idx, remedy in enumerate(remedies, 1):
dosage = extract_dosage_info(remedy['content'])
final_response += f"""\
**آپشن {idx}:**
- **دوا:** {remedy['content'].split(' ')[0]}
- **علامات:** {', '.join(symptoms[:3])}
- **خوارک:** {dosage}
- **طریقہ استعمال:** {"5 قطرے پانی میں" if 'قطرے' in dosage else "2 گولیاں"}
- **دورانیہ:** {"3 دن" if 'حاد' in user_input else "1 ہفتہ"}
- **ماخذ:** [{remedy['title']}]({remedy['link']})
"""
return final_response
# Streamlit UI in Urdu
st.set_page_config(page_title="ہومیوپیتھک ڈاکٹر", page_icon="🌿")
# Urdu interface
st.title("🌐 لائیو ہومیوپیتھک مشیر")
st.markdown("""
<style>
[data-testid="stMarkdownContainer"] ul {
padding-right: 40px;
}
</style>
""", unsafe_allow_html=True)
# Chat history
if "messages" not in st.session_state:
st.session_state.messages = [
{"role": "assistant", "content": "السلام علیکم! آپ کی کیا علامات ہیں؟ مثالوں:\n- سر درد اور چکر آنا\n- کھانسی کے ساتھ بخار\n- پیٹ درد اور بھوک نہ لگنا"}
]
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("اپنی علامات یہاں درج کریں..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
with st.spinner("تجویز تیار کی جا رہی ہے..."):
full_response = homeo_chatbot_urdu(prompt)
st.markdown(full_response)
st.session_state.messages.append({"role": "assistant", "content": full_response})
# Disclaimer
st.markdown("""
---
**⚠️ نوٹس:**
یہ طبی مشورہ نہیں ہے۔ ہمیشہ کوالیفائیڈ ڈاکٹر سے رجوع کریں۔
This is not medical advice. Always consult a qualified practitioner.
""")# app.py
import streamlit as st
from groq import Groq
import os
import requests
from bs4 import BeautifulSoup
import re
from urllib.parse import quote_plus
# Groq API setup
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
# Web scraping functions
def google_search(query):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
encoded_query = quote_plus(query)
url = f"https://www.google.com/search?q={encoded_query}&gl=us&hl=en"
try:
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
results = []
for g in soup.find_all('div', class_='tF2Cxc'):
link = g.find('a')['href']
title = g.find('h3').text
snippet = g.find('div', class_='VwiC3b')
if snippet:
results.append({
'title': title,
'link': link,
'snippet': snippet.text
})
return results[:3] # Return top 3 results
except Exception as e:
st.error(f"سرچ ایرر: {str(e)}")
return []
# Homeopathic dosage extraction (Urdu supported)
def extract_dosage_info(text):
patterns = [
r'(\d+[\s-]*\d*\s*(بار|قطرے|گولیاں|خوارج)\s*(فی دن|روزانہ))',
r'(دن میں \d+\s*بار)',
r'(\d+-\d+\s*گھنٹے کے وقفے سے)'
]
for pattern in patterns:
match = re.search(pattern, text)
if match:
return match.group()
return "دن میں 3 بار (ڈیفالٹ)"
# Chatbot logic
def homeo_chatbot_urdu(user_input):
# Step 1: Symptom extraction in Urdu
symptom_prompt = f"""صارف کی تفصیل: {user_input}
ہومیوپیتھک علامات کو انگلش میں کاما سے علیحدہ فہرست میں نکالیں۔
مثال: headache, dry cough, fever with chills"""
try:
symptom_response = client.chat.completions.create(
messages=[{"role": "user", "content": symptom_prompt}],
model="llama3-70b-8192",
temperature=0.2
)
symptoms = symptom_response.choices[0].message.content.split(", ")
except Exception as e:
return f"ایرر: {str(e)}"
# Step 2: Web search for remedies
search_query = f"homeopathic remedies for {' '.join(symptoms)} site:.edu OR site:.gov"
search_results = google_search(search_query)
remedies = []
for result in search_results:
remedies.append({
'title': result['title'],
'link': result['link'],
'content': result['snippet']
})
# Step 3: Prepare response in Urdu
final_response = "🌿 **تجویز کردہ ہومیوپیتھک علاج:**\n\n"
for idx, remedy in enumerate(remedies, 1):
dosage = extract_dosage_info(remedy['content'])
final_response += f"""\
**آپشن {idx}:**
- **دوا:** {remedy['content'].split(' ')[0]}
- **علامات:** {', '.join(symptoms[:3])}
- **خوارک:** {dosage}
- **طریقہ استعمال:** {"5 قطرے پانی میں" if 'قطرے' in dosage else "2 گولیاں"}
- **دورانیہ:** {"3 دن" if 'حاد' in user_input else "1 ہفتہ"}
- **ماخذ:** [{remedy['title']}]({remedy['link']})
"""
return final_response
# Streamlit UI in Urdu
st.set_page_config(page_title="ہومیوپیتھک ڈاکٹر", page_icon="🌿")
# Urdu interface
st.title("🌐 لائیو ہومیوپیتھک مشیر")
st.markdown("""
<style>
[data-testid="stMarkdownContainer"] ul {
padding-right: 40px;
}
</style>
""", unsafe_allow_html=True)
# Chat history
if "messages" not in st.session_state:
st.session_state.messages = [
{"role": "assistant", "content": "السلام علیکم! آپ کی کیا علامات ہیں؟ مثالوں:\n- سر درد اور چکر آنا\n- کھانسی کے ساتھ بخار\n- پیٹ درد اور بھوک نہ لگنا"}
]
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("اپنی علامات یہاں درج کریں..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
with st.spinner("تجویز تیار کی جا رہی ہے..."):
full_response = homeo_chatbot_urdu(prompt)
st.markdown(full_response)
st.session_state.messages.append({"role": "assistant", "content": full_response})
# Disclaimer
st.markdown("""
---
**⚠️ نوٹس:**
یہ طبی مشورہ نہیں ہے۔ ہمیشہ کوالیفائیڈ ڈاکٹر سے رجوع کریں۔
This is not medical advice. Always consult a qualified practitioner.
""") |