import gradio as gr from transformers import pipeline # Load model generator = pipeline("text-generation", model="microsoft/DialoGPT-medium") def chat(message, history): # Convert history (list of dicts) into a dialogue string conversation = "" if history: for msg in history: if msg["role"] == "user": conversation += f"User: {msg['content']}\n" else: conversation += f"Bot: {msg['content']}\n" conversation += f"User: {message}\nBot:" response = generator(conversation, max_new_tokens=150) reply = response[0]["generated_text"].split("Bot:")[-1].strip() history.append({"role": "user", "content": message}) history.append({"role": "assistant", "content": reply}) return "", history gr.ChatInterface( fn=chat, title="GIMPA Assistant 🤖", description="An AI Workmate powered by DialoGPT (offline and free).", theme="soft", ).launch()