heritiana2026's picture
Update app.py
2477a49 verified
Raw
History Blame Contribute Delete
1.5 kB
import gradio as gr
import os
import sys
# Téléchargement automatique des modèles
os.environ["CHATBOT_MODEL_DIR"] = "utils"
os.environ["HF_REPO_ID"] = "heritiana2026/chatbot-medical-malagasy"
# Importer le service
from chat_services import ChatService # copie chat_services.py dans le Space
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
# APRÈS — compatible toutes versions
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()