Prashanthsrn commited on
Commit
59c99bb
·
verified ·
1 Parent(s): ae6f04f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,15 +1,20 @@
1
  import gradio as gr
2
- from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
3
 
4
  # Load pre-trained model and tokenizer
5
- model_name = "facebook/blenderbot-400M-distill"
6
- tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
7
- model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
8
 
9
  def generate_response(input_text, chat_history=[]):
10
- inputs = tokenizer([input_text], return_tensors="pt")
11
- reply_ids = model.generate(inputs.input_ids, max_length=60, pad_token_id=tokenizer.eos_token_id)
 
 
 
 
12
  response = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
 
13
  chat_history.append((input_text, response))
14
  return chat_history
15
 
@@ -39,7 +44,7 @@ body {
39
 
40
  # Create the Gradio interface
41
  with gr.Blocks(css=custom_css) as demo:
42
- gr.Markdown("# Chat with BlenderBot")
43
  chatbot_ui = gr.Chatbot(label="Chatbot")
44
  input_box = gr.Textbox(show_label=False, placeholder="Type a message...")
45
  chat_history = gr.State([])
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
  # Load pre-trained model and tokenizer
5
+ model_name = "EleutherAI/gpt-neo-2.7B"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
  def generate_response(input_text, chat_history=[]):
10
+ # Combine chat history into a single string
11
+ conversation = " ".join(chat_history + [input_text])
12
+ inputs = tokenizer.encode(conversation, return_tensors="pt")
13
+
14
+ # Generate a response
15
+ reply_ids = model.generate(inputs, max_length=256, pad_token_id=tokenizer.eos_token_id)
16
  response = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
17
+
18
  chat_history.append((input_text, response))
19
  return chat_history
20
 
 
44
 
45
  # Create the Gradio interface
46
  with gr.Blocks(css=custom_css) as demo:
47
+ gr.Markdown("# Chat with GPT-Neo 2.7B")
48
  chatbot_ui = gr.Chatbot(label="Chatbot")
49
  input_box = gr.Textbox(show_label=False, placeholder="Type a message...")
50
  chat_history = gr.State([])