Download app.py from theoo44/OdontoAI: direct link, hf CLI and curl.
- Browser
- Download file 6.15 kB
-
https://huggingface.co/spaces/theoo44/OdontoAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/theoo44/OdontoAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/theoo44/OdontoAI/resolve/main/app.py
6.15 kB
| import gradio as gr | |
| from datetime import datetime | |
| # Base de conocimiento médico | |
| database = { | |
| "enfermedades": { | |
| "Migraña": { | |
| "medicamento": "Sumatriptán", | |
| "dosis": "50mg", | |
| "frecuencia": "Al inicio del dolor, máximo 2 dosis en 24h", | |
| "duracion": "Según necesidad", | |
| "observaciones": "Evitar en pacientes con enfermedad cardiovascular" | |
| }, | |
| "Hipertensión arterial": { | |
| "medicamento": "Losartán", | |
| "dosis": "50mg", | |
| "frecuencia": "1 vez al día", | |
| "duracion": "Crónico", | |
| "observaciones": "Controlar presión arterial semanalmente" | |
| }, | |
| "Infección urinaria": { | |
| "medicamento": "Ciprofloxacino", | |
| "dosis": "500mg", | |
| "frecuencia": "Cada 12 horas", | |
| "duracion": "7 días", | |
| "observaciones": "Tomar con abundante agua" | |
| }, | |
| "Dolor muscular": { | |
| "medicamento": "Ibuprofeno", | |
| "dosis": "400mg", | |
| "frecuencia": "Cada 8 horas", | |
| "duracion": "3-5 días", | |
| "observaciones": "Tomar con alimentos" | |
| }, | |
| "Resfriado común": { | |
| "medicamento": "Paracetamol", | |
| "dosis": "500mg", | |
| "frecuencia": "Cada 6-8 horas", | |
| "duracion": "3 días", | |
| "observaciones": "Mantenerse hidratado" | |
| } | |
| }, | |
| "medicos": { | |
| "Dra. García": { | |
| "especialidad": "Medicina General", | |
| "registro": "MP 12345", | |
| "firma": "Dra. Ana García" | |
| }, | |
| "Dr. López": { | |
| "especialidad": "Cardiología", | |
| "registro": "MP 67890", | |
| "firma": "Dr. Juan López" | |
| } | |
| } | |
| } | |
| def generar_formula_medica(paciente, edad, enfermedad, medico): | |
| if enfermedad not in database["enfermedades"]: | |
| return "Enfermedad no reconocida", "" | |
| info_enfermedad = database["enfermedades"][enfermedad] | |
| info_medico = database["medicos"].get(medico, database["medicos"]["Dra. García"]) | |
| fecha_actual = datetime.now().strftime("%d/%m/%Y") | |
| formula_html = f""" | |
| <div style='font-family: Arial; padding: 20px; border: 1px solid #ddd; border-radius: 10px; max-width: 600px; margin: 20px auto;'> | |
| <div style='text-align: center; border-bottom: 2px solid #3498db; padding-bottom: 10px; margin-bottom: 20px;'> | |
| <h2 style='color: #2c3e50; margin-bottom: 5px;'>FORMULA MÉDICA</h2> | |
| <p style='color: #7f8c8d;'>Fecha: {fecha_actual}</p> | |
| </div> | |
| <div style='margin-bottom: 20px;'> | |
| <h3 style='color: #3498db; margin-bottom: 10px;'>👤 Datos del Paciente</h3> | |
| <p><strong>Nombre:</strong> {paciente}</p> | |
| <p><strong>Edad:</strong> {edad} años</p> | |
| <p><strong>Diagnóstico:</strong> {enfermedad}</p> | |
| </div> | |
| <div style='margin-bottom: 20px;'> | |
| <h3 style='color: #3498db; margin-bottom: 10px;'>💊 Prescripción Médica</h3> | |
| <table style='width: 100%; border-collapse: collapse;'> | |
| <tr> | |
| <td style='border: 1px solid #ddd; padding: 8px;'><strong>Medicamento</strong></td> | |
| <td style='border: 1px solid #ddd; padding: 8px;'>{info_enfermedad['medicamento']}</td> | |
| </tr> | |
| <tr> | |
| <td style='border: 1px solid #ddd; padding: 8px;'><strong>Dosis</strong></td> | |
| <td style='border: 1px solid #ddd; padding: 8px;'>{info_enfermedad['dosis']}</td> | |
| </tr> | |
| <tr> | |
| <td style='border: 1px solid #ddd; padding: 8px;'><strong>Frecuencia</strong></td> | |
| <td style='border: 1px solid #ddd; padding: 8px;'>{info_enfermedad['frecuencia']}</td> | |
| </tr> | |
| <tr> | |
| <td style='border: 1px solid #ddd; padding: 8px;'><strong>Duración</strong></td> | |
| <td style='border: 1px solid #ddd; padding: 8px;'>{info_enfermedad['duracion']}</td> | |
| </tr> | |
| </table> | |
| </div> | |
| <div style='margin-bottom: 20px;'> | |
| <h3 style='color: #3498db; margin-bottom: 10px;'>ℹ️ Observaciones</h3> | |
| <p>{info_enfermedad['observaciones']}</p> | |
| </div> | |
| <div style='display: flex; justify-content: space-between; align-items: center; margin-top: 30px;'> | |
| <div> | |
| <p style='border-top: 1px solid #000; width: 200px; padding-top: 5px;'> | |
| <strong>Firma del médico</strong> | |
| </p> | |
| <p>{info_medico['firma']}</p> | |
| <p>{info_medico['especialidad']} - {info_medico['registro']}</p> | |
| </div> | |
| <img src='https://placehold.co/100x50/3a7bd5/FFFFFF?text=Sello+Médico' | |
| alt='Sello médico oficial con logo de la institución' | |
| style='height: 80px; opacity: 0.8;'/> | |
| </div> | |
| </div> | |
| """ | |
| return formula_html | |
| with gr.Blocks(title="Prescripción Médica Automatizada", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🏥 Sistema de Prescripción Médica Automatizada") | |
| with gr.Row(): | |
| with gr.Column(): | |
| paciente = gr.Textbox(label="Nombre del paciente") | |
| edad = gr.Number(label="Edad", minimum=1, maximum=120) | |
| enfermedad = gr.Dropdown( | |
| label="Diagnóstico/Enfermedad", | |
| choices=list(database["enfermedades"].keys()) | |
| ) | |
| medico = gr.Dropdown( | |
| label="Médico prescriptor", | |
| choices=list(database["medicos"].keys()), | |
| value="Dra. García" | |
| ) | |
| generar_btn = gr.Button("Generar Formula Médica") | |
| with gr.Column(): | |
| formula_medica = gr.HTML() | |
| generar_btn.click( | |
| fn=generar_formula_medica, | |
| inputs=[paciente, edad, enfermedad, medico], | |
| outputs=[formula_medica] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |