Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243# app.pyimport gradio as grdef medical_diagnosis(fever, cough, headache, fatigue):"""Rule-based medical diagnosis function for Gradio GUI.Returns diagnosis and recommendation based on symptoms."""# Nested condition logicif 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."else:return "Diagnosis: Fever of unknown cause. π Recommendation: Monitor and consult 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."else:return "Diagnosis: No significant symptoms detected. β Recommendation: Healthy"# Gradio interfaceinterface = gr.Interface(fn=medical_diagnosis,inputs=[gr.Checkbox(label="Fever"),gr.Checkbox(label="Cough"),gr.Checkbox(label="Headache"),gr.Checkbox(label="Fatigue")],outputs="text",title="π©Ί Interactive Medical Diagnosis System",description="Select your symptoms and click Submit to get a diagnosis and recommendation.")# Launch the appif __name__ == "__main__":interface.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import gradio as grdef advanced_medical_diagnosis(fever, cough, headache, fatigue, sore_throat, shortness_of_breath, nausea, body_ache, diarrhea):"""Advanced rule-based medical diagnosis system.Evaluates multiple symptoms with nested logic to provide diagnosis and recommendations."""# Collect symptomssymptoms = {"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 Truesymptom_count = sum(symptoms.values())# Begin advanced nested diagnosisif fever: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:diagnosis = "β οΈ Fever of unknown origin"recommendation = "π Recommendation: Monitor symptoms and consult a doctor if persists."else: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:diagnosis = "β No significant symptoms detected"recommendation = "π‘ Recommendation: Healthy"# Return detailed resultresult = 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=advanced_medical_diagnosis,inputs=[gr.Checkbox(label="Fever"),gr.Checkbox(label="Cough"),gr.Checkbox(label="Headache"),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=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)if __name__ == "__main__":interface.launch()
app.py+64-23