File size: 8,074 Bytes
5df32b9 | 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | import os
import gradio as gr
from huggingface_hub import InferenceClient
# Configuration officielle connectée à ton modèle fraîchement fusionné
YOUR_USERNAME = "Esteban111"
MODEL_REPO = f"{YOUR_USERNAME}/Aion-Pulse"
# Connexion à ton modèle via l'API Serverless de Hugging Face
client = InferenceClient(MODEL_REPO, token=os.environ.get("HF_TOKEN"))
mistral_vibe_css = """
body, .gradio-container {
background-color: #111214 !important;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}
/* Fix structurel pour empêcher le défilement fou du chat central */
.chatbot-container {
border: none !important;
background: transparent !important;
overflow-y: auto !important;
max-height: 70vh !important;
}
/* --- SIDEBAR GAUCHE ESTEBAN TONDOLO --- */
.sidebar-panel {
background-color: #16171b !important;
border-right: 1px solid #232429 !important;
padding: 20px 16px !important;
height: 100vh !important;
display: flex;
flex-direction: column;
}
.sidebar-header {
display: flex;
justify-content: space-between;
align-items: center;
color: #ffffff;
font-weight: 600;
font-size: 16px;
margin-bottom: 24px;
}
.nav-item {
background: transparent !important;
border: none !important;
color: #a0a1a5 !important;
text-align: left !important;
font-size: 14px !important;
padding: 10px 12px !important;
border-radius: 8px !important;
cursor: pointer !important;
width: 100% !important;
justify-content: flex-start !important;
transition: background-color 0.2s, color 0.2s;
}
.nav-item:hover {
background-color: #232429 !important;
color: #ffffff !important;
}
.sidebar-section-title {
color: #5c5d61;
font-size: 12px;
font-weight: 600;
margin: 20px 0 8px 12px;
text-transform: uppercase;
}
.new-chat-btn {
background: linear-gradient(135deg, #0055ff, #00f0ff) !important;
color: #000000 !important;
font-weight: bold !important;
border: none !important;
border-radius: 10px !important;
margin-top: auto !important;
padding: 12px !important;
cursor: pointer;
}
.new-chat-btn:hover {
box-shadow: 0 0 15px rgba(0, 240, 255, 0.5) !important;
}
.user-profile-box {
display: flex;
align-items: center;
padding: 12px;
border-top: 1px solid #232429;
margin-top: 12px;
justify-content: space-between;
}
.avatar-circle {
width: 32px;
height: 32px;
background-color: #2d3139;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff;
font-weight: bold;
}
/* --- ZONE DU CHAT CENTRAL --- */
.main-layout {
max-width: 800px !important;
margin: 0 auto !important;
padding-top: 4vh !important;
}
.gradio-container .panel, .gradio-container .chatbot {
border: none !important;
background: transparent !important;
box-shadow: none !important;
}
.message-user {
background-color: #1d1e22 !important;
color: #ffffff !important;
}
.message-bot {
background-color: #16171b !important;
color: #ffffff !important;
border-left: 3px solid #00f0ff !important;
}
.gradio-container .button-group {
display: none !important;
}
"""
def system_prompt_bilingual_neurology(message, history):
# Consignes d'alignement pour forcer l'expertise bilingue d'Aion-Pulse
system_instruction = (
"You are Aion-Pulse, a world-class open-source AI specialist in neurology and neurosciences. "
"Tu es Aion-Pulse, une IA open-source d'élite mondiale spécialisée en neurologie et neurosciences. "
"Always respond in the language used by the user (French or English) with absolute clinical precision. "
"Réponds toujours dans la langue de l'utilisateur (français ou anglais) avec une rigueur chirurgicale. "
"You have exhaustive knowledge of neurological conditions (stroke, MS, Parkinson's, gliomas, neuromuscular disorders). "
"Be concise, highly scientific, and avoid any fluff."
)
messages = [{"role": "system", "content": system_instruction}]
for turn in history:
messages.append({"role": turn["role"], "content": turn["content"]})
messages.append({"role": "user", "content": message})
try:
response_stream = client.chat_completion(
messages=messages,
max_tokens=1024,
stream=True,
temperature=0.25
)
text = ""
for chunk in response_stream:
token = chunk.choices.delta.content
if token:
text += token
yield text
except Exception as e:
yield f"⚠️ Synchronisation avec Aion-Pulse en cours. Si l'erreur persiste, vérifie le secret HF_TOKEN. Erreur : {str(e)}"
with gr.Blocks() as demo:
with gr.Row():
# COLONNE DE GAUCHE : SIDEBAR INTERACTIVE
with gr.Column(scale=2, elem_classes=["sidebar-panel"], min_width=260):
gr.HTML("<div class='sidebar-header'><span>Work ▾</span><span style='cursor:pointer;'>🔍</span></div>")
skill_btn = gr.Button("💎 Skills", elem_classes=["nav-item"])
conn_btn = gr.Button("🔌 Connecteurs", elem_classes=["nav-item"])
inst_btn = gr.Button("📝 Instructions", elem_classes=["nav-item"])
gr.HTML("<div class='sidebar-section-title'>Projets</div>")
proj_btn = gr.Button("➕ Nouveau projet", elem_classes=["nav-item"])
gr.HTML("<div class='sidebar-section-title' style='margin-top:20px;'>Historique</div>")
gr.HTML("<div style='color:#5c5d61; font-size:13px; padding-left:12px; font-style:italic;'>Aucun chat.</div>")
new_chat_btn = gr.Button("⊕ Nouveau chat", elem_classes=["new-chat-btn"])
gr.HTML("""
<div class='user-profile-box'>
<div style='display: flex; align-items: center; gap: 10px;'>
<div class='avatar-circle'>ET</div>
<div>
<div style='color: white; font-size: 14px; font-weight: 600;'>Esteban Tondolo</div>
<div style='color: #5c5d61; font-size: 11px;'>Free Plan</div>
</div>
</div>
<span style='color: #5c5d61; cursor: pointer;'>↕</span>
</div>
""")
# COLONNE DE DROITE : INTERFACE CHAT DUPLICATION DIRECTE MISTRAL VIBE
with gr.Column(scale=8, elem_classes=["main-layout"]):
chatter = gr.ChatInterface(
fn=system_prompt_bilingual_neurology,
type="messages",
placeholder=gr.HTML("""
<div style='text-align:center; padding-top:10vh;'>
<div style='color:#00f0ff; font-size:50px; font-weight:900; text-shadow: 0 0 20px rgba(0,240,255,0.4); margin-bottom:10px;'>⦵</div>
<h1 style='color:white; font-size:28px; font-weight:500; margin-bottom:40px;'>Que souhaitez-vous faire ? / What would you like to do?</h1>
</div>
"""),
examples=[
"Analyse les symptômes : tremblement de repos asymétrique, rigidité plastique et akinésie.",
"Differentiate between ischemic stroke and hemorrhagic stroke management in the first golden hour."
],
textbox=gr.Textbox(placeholder="Posez une question en neurologie (FR/EN) à Aion-Pulse...", container=False, scale=8),
submit_btn=gr.Button("➔", variant="primary", scale=1, min_width=40)
)
# Action de reset sur le clic du bouton "Nouveau chat" de la Sidebar
new_chat_btn.click(fn=lambda: None, outputs=None, clicks=chatter.clear)
if __name__ == "__main__":
demo.launch(css=mistral_vibe_css, theme=gr.themes.Monochrome()) |