abdull4h commited on
Commit
8db55ce
·
verified ·
1 Parent(s): ba78a0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -2,18 +2,18 @@ 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)}"
@@ -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="Local Chatbot using Transformers",
27
- description="A simple chat application running a local model with Hugging Face Transformers."
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__":