Homeo_doctor / app.py
aminahmed78's picture
Update app.py
2ccd913 verified
raw
history blame
2.11 kB
# app.py (Updated Version)
def multilingual_chatbot(user_input):
try:
# Detect input language
lang = detect(user_input)
# Step 1: Symptom extraction with homeopathy focus
symptom_prompt = f"""Extract ONLY homeopathic-relevant symptoms from this text as English comma-separated list:
{user_input}
Example Output: stinging pain, anxiety worse evenings, thirstlessness"""
symptom_response = client.chat.completions.create(
messages=[{"role": "user", "content": symptom_prompt}],
model="llama3-70b-8192",
temperature=0.1
)
symptoms = symptom_response.choices[0].message.content.split(", ")
# Step 2: Focused homeopathic web search
search_query = (
f"homeopathic remedy for {' '.join(symptoms)} "
f"(site:.edu OR site:.gov) "
f"-allopathic -conventional -pharmaceutical"
)
results = google_search(search_query)
# Filter homeopathic-specific results
homeo_keywords = ['homeopath', 'remedy', 'potency', 'materia medica']
filtered_results = [
r for r in results
if any(kw in r['snippet'].lower() for kw in homeo_keywords)
]
# Step 3: Generate strict homeopathic response
response_prompt = f"""You are a homeopathic doctor. Recommend ONLY homeopathic medicines in {lang} for these symptoms: {', '.join(symptoms)}.
Use this research data: {[r['snippet'] for r in filtered_results]}
Include:
- Medicine name in English
- Potency (like 30C, 200CK)
- Administration method
- Key symptoms it addresses
- Source reference"""
final_response = client.chat.completions.create(
messages=[{"role": "user", "content": response_prompt}],
model="llama3-70b-8192",
temperature=0.3
)
return final_response.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"