| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| chatbot = pipeline("text-generation", model="distilgpt2") |
|
|
| def respond(message, history): |
| |
| prompt = "" |
| for user, bot in history: |
| prompt += f"User: {user}\nBot: {bot}\n" |
| prompt += f"User: {message}\nBot:" |
|
|
| |
| response = chatbot( |
| prompt, |
| max_length=200, |
| do_sample=True, |
| temperature=0.7 |
| ) |
|
|
| bot_reply = response[0]["generated_text"].split("Bot:")[-1].strip() |
| return bot_reply |
|
|
| |
| demo = gr.ChatInterface( |
| respond, |
| title="💬 WhatsApp-Style AI Chatbot", |
| description="Type a message and chat with AI" |
| ) |
|
|
| demo.launch() |
|
|