thesven commited on
Commit
b9570bd
1 Parent(s): 8d1c487
Files changed (2) hide show
  1. app.py +14 -5
  2. requirements.txt +1 -0
app.py CHANGED
@@ -32,12 +32,21 @@ def start():
32
 
33
  return "Model loaded and ready!"
34
 
35
- def send_message(input_text):
36
  global tokenizer, model
 
 
 
 
 
37
  input_ids = tokenizer(input_text, return_tensors='pt').input_ids.cuda()
38
  output = model.generate(inputs=input_ids, max_new_tokens=50)
39
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
40
- return generated_text
 
 
 
 
41
 
42
  with gr.Blocks() as demo:
43
  gr.Markdown("# Chat with the Model")
@@ -45,12 +54,12 @@ with gr.Blocks() as demo:
45
  start_button = gr.Button("Start Model")
46
  status_text = gr.Textbox(label="Status")
47
 
48
- start()
49
 
50
- chatbox = gr.Chatbot()
51
  message = gr.Textbox(label="Your Message")
52
  send_button = gr.Button("Send")
53
 
54
- send_button.click(send_message, inputs=message, outputs=chatbox)
55
 
56
  demo.launch()
 
32
 
33
  return "Model loaded and ready!"
34
 
35
+ def send_message(message, history):
36
  global tokenizer, model
37
+ # Add the user's message to the history
38
+ history.append(("User", message))
39
+
40
+ # Generate the model's response
41
+ input_text = " ".join([msg for _, msg in history])
42
  input_ids = tokenizer(input_text, return_tensors='pt').input_ids.cuda()
43
  output = model.generate(inputs=input_ids, max_new_tokens=50)
44
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
45
+
46
+ # Add the model's response to the history
47
+ history.append(("Bot", generated_text))
48
+
49
+ return history, history
50
 
51
  with gr.Blocks() as demo:
52
  gr.Markdown("# Chat with the Model")
 
54
  start_button = gr.Button("Start Model")
55
  status_text = gr.Textbox(label="Status")
56
 
57
+ start_button.click(start, inputs=None, outputs=status_text)
58
 
59
+ chatbot = gr.Chatbot()
60
  message = gr.Textbox(label="Your Message")
61
  send_button = gr.Button("Send")
62
 
63
+ send_button.click(send_message, inputs=[message, chatbot], outputs=[chatbot, chatbot])
64
 
65
  demo.launch()
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  accelerate
2
  bitsandbytes
3
  transformers
 
 
1
  accelerate
2
  bitsandbytes
3
  transformers
4
+ spaces