Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load GPT-2 chat model
|
5 |
+
chatbot = pipeline("text-generation", model="gpt2")
|
6 |
+
|
7 |
+
# Function to handle the chatbot interaction
|
8 |
+
def chat_with_gpt2(messages):
|
9 |
+
prompt = messages[-1][1] # Get the latest message from the user
|
10 |
+
response = chatbot(prompt, max_length=100, num_return_sequences=1)
|
11 |
+
return messages + [(response[0]['generated_text'], "GPT-2")]
|
12 |
+
|
13 |
+
# Create a Gradio Chatbot interface
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=chat_with_gpt2,
|
16 |
+
inputs=gr.Chatbot(),
|
17 |
+
outputs=gr.Chatbot(),
|
18 |
+
title="Chat with GPT-2",
|
19 |
+
description="A simple chat app using GPT-2"
|
20 |
+
)
|
21 |
+
|
22 |
+
iface.launch()
|