Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,18 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
import torch
|
4 |
|
5 |
-
# Load the
|
6 |
chatbot = pipeline(
|
7 |
-
"
|
8 |
model="facebook/blenderbot-400M-distill",
|
9 |
device=0 if torch.cuda.is_available() else -1
|
10 |
)
|
11 |
|
12 |
def chat(user_input):
|
13 |
try:
|
14 |
-
#
|
15 |
-
response = chatbot(
|
16 |
-
# Return the generated
|
17 |
return response[0]['generated_text']
|
18 |
except Exception as e:
|
19 |
return f"An error occurred: {str(e)}"
|
@@ -23,8 +23,8 @@ iface = gr.Interface(
|
|
23 |
fn=chat,
|
24 |
inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
|
25 |
outputs="text",
|
26 |
-
title="
|
27 |
-
description="A simple chat application
|
28 |
)
|
29 |
|
30 |
if __name__ == "__main__":
|
|
|
2 |
from transformers import pipeline
|
3 |
import torch
|
4 |
|
5 |
+
# Load the text generation pipeline with the model
|
6 |
chatbot = pipeline(
|
7 |
+
"text-generation",
|
8 |
model="facebook/blenderbot-400M-distill",
|
9 |
device=0 if torch.cuda.is_available() else -1
|
10 |
)
|
11 |
|
12 |
def chat(user_input):
|
13 |
try:
|
14 |
+
# Generate response
|
15 |
+
response = chatbot(user_input, max_length=100, do_sample=True)
|
16 |
+
# Return the generated text
|
17 |
return response[0]['generated_text']
|
18 |
except Exception as e:
|
19 |
return f"An error occurred: {str(e)}"
|
|
|
23 |
fn=chat,
|
24 |
inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
|
25 |
outputs="text",
|
26 |
+
title="Chatbot using Blenderbot",
|
27 |
+
description="A simple chat application using the Blenderbot model."
|
28 |
)
|
29 |
|
30 |
if __name__ == "__main__":
|