| import gradio as gr |
| import os |
| import sys |
|
|
| |
| os.environ["CHATBOT_MODEL_DIR"] = "utils" |
| os.environ["HF_REPO_ID"] = "heritiana2026/chatbot-medical-malagasy" |
|
|
| |
| from chat_services import ChatService |
| svc = ChatService.get() |
| last_cat = None |
|
|
| def repondre(message, history): |
| global last_cat |
| result = svc.chat(message, session_last_cat=last_cat) |
|
|
| if result["type"] == "salutation": |
| return result["response"] |
|
|
| if result.get("categorie"): |
| last_cat = result["categorie"] |
|
|
| reponse = result.get("generated", "") |
|
|
| if result["type"] == "medical": |
| icon = result.get("icon", "🏥") |
| categorie = result.get("categorie", "") |
| conf = result.get("confidence", 0) |
| indicator = result.get("indicator", "") |
| couleur = {"green": "🟢", "yellow": "🟡", "red": "🔴"}.get(indicator, "⚪") |
| reponse = f"{icon} **{categorie}** {couleur} {conf}%\n\n{reponse}" |
|
|
| return reponse |
|
|
| |
| demo = gr.ChatInterface( |
| fn = repondre, |
| title = "🏥 Chatbot Médical Malagasy", |
| description = "Soraty ny soritr'aretinao amin'ny teny malagasy", |
| examples = [ |
| "Salama", |
| "Marary ny lohako", |
| "Voan'ny tazo aho", |
| "Mivalana be aho", |
| "Bonjour cava toi", |
| "dgztfregde", |
| "Veloma", |
| ], |
| ) |
|
|
| demo.launch() |