File size: 1,495 Bytes
e295689
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c711ac3
e295689
 
 
 
 
 
 
 
 
2477a49
 
 
e295689
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()