import gradio as gr from transformers import pipeline # Charger le modèle pipe = pipeline("text-generation", model="Leo71288/Iva_CLM_V1") # Fonction de chat def chat(user_input, history): history = history or [] # Concaténer l'historique si tu veux du contexte prompt = "\n".join([f"Utilisateur: {u}\nBot: {b}" for u, b in history]) + f"\nUtilisateur: {user_input}\nBot:" output = pipe(prompt, max_new_tokens=200, do_sample=True, temperature=0.7)[0]["generated_text"] # Extraire seulement la réponse après "Bot:" bot_reply = output.split("Bot:")[-1].strip() history.append((user_input, bot_reply)) return history, history # Lancement Gradio chatbot = gr.Chatbot() iface = gr.Interface( fn=chat, inputs=["text", "state"], outputs=[chatbot, "state"], title="🤖 Chat avec Iva_CLM_V1", description="Un chatbot basé sur HuggingFace Transformers." ) iface.launch()