Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
import torch
|
4 |
|
5 |
# Load the conversational pipeline with the model
|
6 |
chatbot = pipeline(
|
7 |
"conversational",
|
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 |
-
# Initialize a conversation with the user's message
|
15 |
-
conversation = Conversation(user_input)
|
16 |
# Process the conversation with the model
|
17 |
-
|
18 |
-
# Return the
|
19 |
-
return
|
20 |
except Exception as e:
|
21 |
return f"An error occurred: {str(e)}"
|
22 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
import torch
|
4 |
|
5 |
# Load the conversational pipeline with the model
|
6 |
chatbot = pipeline(
|
7 |
"conversational",
|
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 |
# Process the conversation with the model
|
15 |
+
response = chatbot({"text": user_input})
|
16 |
+
# Return the generated response
|
17 |
+
return response[0]['generated_text']
|
18 |
except Exception as e:
|
19 |
return f"An error occurred: {str(e)}"
|
20 |
|