Spaces:
Sleeping
Sleeping
Update app.py
Browse files11243456677899101112131415161718192021222324252627111213141516282930313233343536373839401841424320212223444546474849502551525354555657585960616263642965666768693470717273747576363738777879808182418384# app.pyimport gradio as gr
def medical_diagnosis(fever, cough, headache, fatigue):def advanced_medical_diagnosis( fever, cough, headache, fatigue, sore_throat, shortness_of_breath, nausea, body_ache, diarrhea): """ Rule-based medical diagnosis function for Gradio GUI. Returns diagnosis and recommendation based on symptoms. Advanced rule-based medical diagnosis system. Evaluates multiple symptoms with nested logic to provide diagnosis and recommendations. """ # Nested condition logic # Collect symptoms symptoms = { "Fever": fever, "Cough": cough, "Headache": headache, "Fatigue": fatigue, "Sore Throat": sore_throat, "Shortness of Breath": shortness_of_breath, "Nausea": nausea, "Body Ache": body_ache, "Diarrhea": diarrhea }
# Count how many symptoms are True symptom_count = sum(symptoms.values())
# Begin advanced nested diagnosis if fever: if cough and headache: return "Diagnosis: Possible Flu. π Recommendation: Consult a doctor and rest." elif cough: return "Diagnosis: Possible Cold. π Recommendation: Drink fluids and rest." elif headache: return "Diagnosis: Possible Migraine. π Recommendation: Take pain relief medication." if cough and shortness_of_breath and body_ache: diagnosis = "π¦ Possible COVID-19 infection" recommendation = "π Recommendation: Get tested immediately, isolate yourself, and consult a doctor." elif cough and sore_throat and headache: diagnosis = "π€§ Possible Flu" recommendation = "π Recommendation: Rest, hydrate, and consult a doctor if symptoms worsen." elif headache and nausea: diagnosis = "π€ Possible Migraine" recommendation = "π Recommendation: Take pain relief, rest in a dark quiet room." elif diarrhea and nausea: diagnosis = "π€’ Possible Food Poisoning" recommendation = "π Recommendation: Stay hydrated and consult a doctor if severe." else: return "Diagnosis: Fever of unknown cause. π Recommendation: Monitor and consult doctor if persists." diagnosis = "β οΈ Fever of unknown origin" recommendation = "π Recommendation: Monitor symptoms and consult a doctor if persists." else: if headache and fatigue: return "Diagnosis: Possible Stress or Mild Infection. π Recommendation: Rest and hydrate." elif fatigue: return "Diagnosis: Possible Fatigue due to lack of sleep. π Recommendation: Rest." if fatigue and headache and body_ache: diagnosis = "π΄ Possible Stress or Mild Infection" recommendation = "π Recommendation: Rest, hydrate, and reduce stress." elif fatigue and diarrhea: diagnosis = "π§ Possible Dehydration" recommendation = "π Recommendation: Drink plenty of fluids and rest." else: return "Diagnosis: No significant symptoms detected. β
Recommendation: Healthy" diagnosis = "β
No significant symptoms detected" recommendation = "π‘ Recommendation: Healthy"
# Return detailed result result = f"### Diagnosis Result\n**Diagnosis:** {diagnosis}\n\n**Symptoms Reported:**\n" for symptom, present in symptoms.items(): status = "β
Yes" if present else "β No" result += f"- {symptom}: {status}\n" result += f"\n**{recommendation}**" return result
# Gradio interfaceinterface = gr.Interface( fn=medical_diagnosis, fn=advanced_medical_diagnosis, inputs=[ gr.Checkbox(label="Fever"), gr.Checkbox(label="Cough"), gr.Checkbox(label="Headache"), gr.Checkbox(label="Fatigue") gr.Checkbox(label="Fatigue"), gr.Checkbox(label="Sore Throat"), gr.Checkbox(label="Shortness of Breath"), gr.Checkbox(label="Nausea"), gr.Checkbox(label="Body Ache"), gr.Checkbox(label="Diarrhea") ], outputs="text", title="π©Ί Interactive Medical Diagnosis System", description="Select your symptoms and click Submit to get a diagnosis and recommendation." outputs=gr.Markdown(), title="π©Ί Advanced Medical Diagnosis System", description="Select all the symptoms you are experiencing and click Submit to get a detailed diagnosis and recommendation.", live=False)
# Launch the appif __name__ == "__main__": interface.launch()app.py+64-23