chat-ui / app.py
isitcoding's picture
Update app.py
372f4a2 verified
raw
history blame
1.16 kB
import gradio as gr
import random
from transformers import pipeline
# Load the text generation pipeline with your fine-tuned model
generator = pipeline('text-generation', model='isitcoding/gpt2_120_finetuned')
# Function to generate responses using the text generation model
def respond(message, chat_history):
# Generate a response from the model
response = generator(message, max_length=1028, num_return_sequences=3)[0]['generated_text']
# Append the user message and model response to chat history
chat_history.append(("User", message))
chat_history.append(("Bot", response))
return chat_history
# Create a Gradio interface using Blocks
with gr.Blocks() as demo:
# Add a Chatbot component
chatbot = gr.Chatbot()
# Add a textbox for user input
msg = gr.Textbox(label="Enter your message")
# Add a button to clear the chat
clear = gr.Button("Clear")
# Define what happens when the user submits a message
msg.submit(respond, [msg, chatbot], chatbot)
# Define what happens when the clear button is pressed
clear.click(lambda: [], None, chatbot)
# Launch the Gradio interface
demo.launch()