Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the GPT-2 model
|
| 5 |
+
gpt2 = pipeline("text-generation", model="gpt2")
|
| 6 |
|
| 7 |
+
# Define the function that will generate the response
|
| 8 |
+
def chat_with_gpt2(user_input):
|
| 9 |
+
# Use the GPT-2 model to generate a response
|
| 10 |
+
responses = gpt2(user_input, max_length=100, num_return_sequences=1)
|
| 11 |
+
# Return the first (and only) response
|
| 12 |
+
return responses[0]['generated_text']
|
| 13 |
+
|
| 14 |
+
# Create the Gradio interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=chat_with_gpt2,
|
| 17 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Type your message here..."),
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="Chat with GPT-2",
|
| 20 |
+
description="This is a simple chatbot powered by GPT-2. Type your message and get a response."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Launch the app
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
iface.launch()
|