chat / app.py
Skander453's picture
Create app.py
1a00d25 verified
Raw
History Blame Contribute Delete
428 Bytes
import gradio as gr
from transformers import pipeline
# Charger le modèle UNE seule fois
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
def chat(message, history):
# Traduction
translated = translator(message)[0]['translation_text']
# Ajouter au chat
history.append((message, translated))
return history
# Interface chat
demo = gr.ChatInterface(fn=chat)
demo.launch()