File size: 1,067 Bytes
a485c36
9fb9c1e
 
3bfbf73
37412c9
9fb9c1e
 
3bfbf73
 
 
9fb9c1e
 
 
3bfbf73
9fb9c1e
 
 
 
 
 
 
 
 
 
 
3bfbf73
 
 
 
 
9fb9c1e
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
from transformers import pipeline

# Load the chatbot model using text-generation pipeline
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")

def respond(message, chat_history):
    # Generate a response using the model
    response = chatbot(message, max_new_tokens=100)[0]['generated_text']
    # Update chat history
    chat_history = chat_history or []
    chat_history.append(("User", message))
    chat_history.append(("Bot", response))
    # Format chat history for display
    chat_display = ""
    for speaker, text in chat_history:
        chat_display += f"{speaker}: {text}\n"
    return chat_display, chat_history

with gr.Blocks() as demo:
    chat_history = gr.State([])
    chatbot_output = gr.Textbox(label="Chatbot Output", lines=15)
    user_input = gr.Textbox(label="Your Message")
    send_button = gr.Button("Send")

    send_button.click(
        fn=respond,
        inputs=[user_input, chat_history],
        outputs=[chatbot_output, chat_history]
    )

if __name__ == "__main__":
    demo.launch()