Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import joblib | |
| import json | |
| model = joblib.load("model_pipeline.joblib") | |
| with open("labels.json", "r") as f: | |
| labels = json.load(f) | |
| label_to_index = {i+1: labels[i] for i in range(len(labels))} | |
| icons = { | |
| 1: "1-🔴🔥 Emergência", | |
| 2: "2-🟠⚠️ Muito Urgente", | |
| 3: "3-🟡 Atenção", | |
| 4: "4-🟢 Estável", | |
| 5: "5-🔵 Baixa Prioridade" | |
| } | |
| colors = { | |
| 1: "#ff4d4d", | |
| 2: "#ff944d", | |
| 3: "#ffd24d", | |
| 4: "#8cd98c", | |
| 5: "#66b3ff" | |
| } | |
| def prever_triagem(texto, idade, dias, doencas): | |
| try: | |
| entrada = [ | |
| f"{texto}. Idade: {idade}. Dias: {dias}. Doenças: {doencas}" | |
| ] | |
| prob = model.predict_proba(entrada)[0] | |
| pred = model.predict(entrada)[0] | |
| if isinstance(pred, str): | |
| nivel = labels.index(pred) + 1 | |
| else: | |
| nivel = int(pred) | |
| html_block = f""" | |
| <div style=" | |
| padding: 20px; | |
| border-radius: 12px; | |
| background-color: {colors[nivel]}; | |
| color: white; | |
| font-size: 22px; | |
| font-weight: bold; | |
| text-align: center;"> | |
| {icons[nivel]} | |
| </div> | |
| """ | |
| return html_block | |
| except Exception as e: | |
| return f"<p style='color:red;'>Erro: {str(e)}</p>" | |
| interface = gr.Interface( | |
| fn=prever_triagem, | |
| inputs=[ | |
| gr.Textbox(lines=3, label="Descreva os sintomas"), | |
| gr.Number(label="Idade"), | |
| gr.Number(label="Dias de sintomas"), | |
| gr.Textbox(label="Doenças/Alergias") | |
| ], | |
| outputs=gr.HTML(label="Classificação"), | |
| title="Sistema Inteligente de Triagem Médica", | |
| description="Classificação por nível de risco." | |
| ) | |
| interface.launch() | |