abdull4h commited on
Commit
ba78a0f
·
verified ·
1 Parent(s): 9a1a441

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -1,22 +1,20 @@
1
  import gradio as gr
2
- from transformers import pipeline, Conversation
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 # Use GPU if available
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
- updated_conversation = chatbot(conversation)
18
- # Return the latest generated response
19
- return updated_conversation.generated_responses[-1]
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