dmayhem93 commited on
Commit
e4f8042
1 Parent(s): 26dd269

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -22,12 +22,13 @@ def user(message, history):
22
  return "", history + [[message, ""]]
23
 
24
 
25
- def chat(history):
26
  chat = []
27
  for item in history:
28
  chat.append({"role": "user", "content": item[0]})
29
  if item[1] is not None:
30
  chat.append({"role": "assistant", "content": item[1]})
 
31
  messages = tok.apply_chat_template(chat, tokenize=False)
32
  # Tokenize the messages string
33
  model_inputs = tok([messages], return_tensors="pt")
@@ -58,28 +59,28 @@ def chat(history):
58
  return partial_text
59
 
60
 
61
- with gr.Blocks() as demo:
62
- # history = gr.State([])
63
- gr.Markdown("## Stable LM 2 Zephyr 1.6b")
64
- gr.HTML('''<center><a href="https://huggingface.co/spaces/stabilityai/stablelm-2-1_6b-zephyr?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space to skip the queue and run in a private space</center>''')
65
- chatbot = gr.Chatbot().style(height=500)
66
- with gr.Row():
67
- with gr.Column():
68
- msg = gr.Textbox(label="Chat Message Box", placeholder="Chat Message Box",
69
- show_label=False).style(container=False)
70
- with gr.Column():
71
- with gr.Row():
72
- submit = gr.Button("Submit")
73
- stop = gr.Button("Stop")
74
- clear = gr.Button("Clear")
75
-
76
- submit_event = msg.submit(fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).then(
77
- fn=chat, inputs=[chatbot], outputs=[chatbot], queue=True)
78
- submit_click_event = submit.click(fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).then(
79
- fn=chat, inputs=[chatbot], outputs=[chatbot], queue=True)
80
- stop.click(fn=None, inputs=None, outputs=None, cancels=[
81
- submit_event, submit_click_event], queue=False)
82
- clear.click(lambda: None, None, [chatbot], queue=False)
83
 
 
 
 
 
 
 
 
 
84
  demo.queue(max_size=32, concurrency_count=2)
85
  demo.launch()
 
22
  return "", history + [[message, ""]]
23
 
24
 
25
+ def chat(message, history):
26
  chat = []
27
  for item in history:
28
  chat.append({"role": "user", "content": item[0]})
29
  if item[1] is not None:
30
  chat.append({"role": "assistant", "content": item[1]})
31
+ chat.append({"role": "user", "content": message})
32
  messages = tok.apply_chat_template(chat, tokenize=False)
33
  # Tokenize the messages string
34
  model_inputs = tok([messages], return_tensors="pt")
 
59
  return partial_text
60
 
61
 
62
+ # with gr.Blocks() as demo:
63
+ # # history = gr.State([])
64
+ # gr.Markdown("## Stable LM 2 Zephyr 1.6b")
65
+ # gr.HTML('''<center><a href="https://huggingface.co/spaces/stabilityai/stablelm-2-1_6b-zephyr?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space to skip the queue and run in a private space</center>''')
66
+ # chatbot = gr.Chatbot().style(height=500)
67
+ # with gr.Row():
68
+ # with gr.Column():
69
+ # msg = gr.Textbox(label="Chat Message Box", placeholder="Chat Message Box",
70
+ # show_label=False).style(container=False)
71
+ # with gr.Column():
72
+ # with gr.Row():
73
+ # submit = gr.Button("Submit")
74
+ # stop = gr.Button("Stop")
75
+ # clear = gr.Button("Clear")
 
 
 
 
 
 
 
 
76
 
77
+ # submit_event = msg.submit(fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).then(
78
+ # fn=chat, inputs=[chatbot], outputs=[chatbot], queue=True)
79
+ # submit_click_event = submit.click(fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).then(
80
+ # fn=chat, inputs=[chatbot], outputs=[chatbot], queue=True)
81
+ # stop.click(fn=None, inputs=None, outputs=None, cancels=[
82
+ # submit_event, submit_click_event], queue=False)
83
+ # clear.click(lambda: None, None, [chatbot], queue=False)
84
+ demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Stable LM 2 Zephyr 1.6b")
85
  demo.queue(max_size=32, concurrency_count=2)
86
  demo.launch()