DreamGenAI's picture
Update app.py
6c66f70 verified
raw
history blame contribute delete
713 Bytes
import gradio as gr
from transformers import pipeline, set_seed
# Load GPT-2 model
generator = pipeline("text-generation", model="gpt2")
set_seed(42)
# Define chatbot response function
def chat_with_bot(message):
prompt = f"User: {message}\nBot:"
response = generator(prompt, max_length=100, do_sample=True, temperature=0.7)
reply = response[0]["generated_text"][len(prompt):] # extract only the new response
return reply.strip()
# Create Gradio interface
gr.Interface(
fn=chat_with_bot,
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
outputs="text",
title="Jayalakshmi's AI Chatbot",
description="A simple chatbot powered by GPT-2. Ask anything!"
).launch()