my-chat / app.py
vedarshatarun69's picture
Update app.py
7997e4f verified
raw
history blame contribute delete
712 Bytes
import gradio as gr
from transformers import pipeline
# Tiny, CPU-friendly model
chatbot_pipeline = pipeline("text-generation", model="sshleifer/tiny-gpt2")
def chat(message, history=[]):
result = chatbot_pipeline(message, max_new_tokens=50)
reply = result[0]['generated_text'].replace(message, "").strip()
history.append((message, reply))
return history, history
with gr.Blocks() as demo:
gr.Markdown("## 🤖 Permanent Tiny AI Chatbot")
chat_ui = gr.Chatbot()
msg = gr.Textbox(label="Type your message here")
clear = gr.Button("Clear Chat")
msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
clear.click(lambda: None, None, chat_ui, queue=False)
demo.launch()