Spaces:
Sleeping
Sleeping
File size: 2,108 Bytes
2ccd913 256d4fe 3fdc359 256d4fe 2ccd913 256d4fe 2ccd913 256d4fe 3fdc359 2ccd913 3fdc359 f0144dd 2ccd913 256d4fe 2ccd913 256d4fe 5b3c8c9 256d4fe 5b3c8c9 256d4fe 5b3c8c9 2ccd913 |
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 |
# 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)}" |