""" Homeopathic Analyzer - Simple Working Version """ import gradio as gr import re from difflib import get_close_matches # ==================== SIMPLE DATABASE ==================== REMEDIES = { "Arnica Montana": { "description": "For trauma, injuries, bruising", "indications": ["injury", "bruise", "trauma", "sore", "shock"], "potency": "30C", "dosage": "Every 2-4 hours" }, "Belladonna": { "description": "Sudden fever, throbbing headache", "indications": ["fever", "headache", "inflammation", "red", "hot"], "potency": "30C", "dosage": "Every 1-2 hours" }, "Nux Vomica": { "description": "Digestive issues, irritability", "indications": ["digestive", "nausea", "irritable", "constipation", "hangover"], "potency": "6C", "dosage": "3 times daily" }, "Pulsatilla": { "description": "Changeable symptoms, weepy", "indications": ["changeable", "weepy", "colds", "digestive", "emotional"], "potency": "30C", "dosage": "Every 4 hours" }, "Bryonia Alba": { "description": "Worse from motion, thirsty", "indications": ["thirsty", "motion", "dry", "constipation", "joint pain"], "potency": "30C", "dosage": "Every 4 hours" } } # Common misspellings MISSPELLINGS = { "arnika": "Arnica Montana", "arnicum": "Arnica Montana", "belladona": "Belladonna", "nux vom": "Nux Vomica", "nuxvomica": "Nux Vomica", "pulsatila": "Pulsatilla", "bryonia": "Bryonia Alba", "argentum nitric": "Argentum Nitricum", "argentic nitric": "Argentum Nitricum" } # ==================== SIMPLE SEARCH ==================== def search_medicine_simple(query): """Simple search that actually works""" if not query or len(query) < 2: return [] query = query.lower().strip() results = [] # Check exact matches for name, data in REMEDIES.items(): if query in name.lower(): results.append({ "name": name, "match": "exact", "confidence": 100, "data": data }) # Check misspellings if query in MISSPELLINGS: correct_name = MISSPELLINGS[query] results.append({ "name": correct_name, "match": "corrected", "confidence": 90, "data": REMEDIES.get(correct_name, {}) }) # Check partial matches for name, data in REMEDIES.items(): name_lower = name.lower() if query in name_lower and not any(r["name"] == name for r in results): results.append({ "name": name, "match": "partial", "confidence": 80, "data": data }) # Check indications for name, data in REMEDIES.items(): for indication in data["indications"]: if query in indication.lower() and not any(r["name"] == name for r in results): results.append({ "name": name, "match": "indication", "confidence": 70, "data": data }) # Remove duplicates unique_results = [] seen = set() for r in results: if r["name"] not in seen: seen.add(r["name"]) unique_results.append(r) # Sort by confidence unique_results.sort(key=lambda x: x["confidence"], reverse=True) return unique_results[:5] # ==================== SIMPLE ANALYSIS ==================== def analyze_symptoms_simple(complaint, aggravations="", ameliorations="", emotional=""): """Simple analysis that actually works""" if not complaint: return [] complaint_lower = complaint.lower() aggravations_lower = aggravations.lower() ameliorations_lower = ameliorations.lower() emotional_lower = emotional.lower() matches = [] for remedy_name, remedy_data in REMEDIES.items(): score = 0 # Check complaint against indications for indication in remedy_data["indications"]: if indication in complaint_lower: score += 30 elif any(word in complaint_lower for word in indication.split()): score += 15 # Simple modality checking if "motion" in aggravations_lower and "bryonia" in remedy_name.lower(): score += 20 if "cold" in aggravations_lower and "arnica" in remedy_name.lower(): score += 20 if "heat" in aggravations_lower and "belladonna" in remedy_name.lower(): score += 20 if score > 10: matches.append({ "name": remedy_name, "score": min(100, score), "data": remedy_data, "reasons": get_match_reasons(complaint_lower, remedy_data) }) # Sort and return matches.sort(key=lambda x: x["score"], reverse=True) return matches[:3] def get_match_reasons(complaint, remedy_data): """Get simple match reasons""" reasons = [] for indication in remedy_data["indications"][:2]: if indication in complaint: reasons.append(f"Matches: {indication}") return reasons[:2] # ==================== GRADIO UI ==================== def create_search_results_html(results, query): """Create HTML for search results""" if not results: return f"""
Try: Arnica, Belladonna, Nux Vomica, Pulsatilla
{result['data']['description']}
Try describing your symptoms in more detail.
{top_match['data']['description']}