Tonic commited on
Commit
7fc9307
1 Parent(s): acf224c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -18,7 +18,6 @@ model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_c
18
 
19
  @spaces.GPU
20
  def generate_response(user_input, max_new_tokens, temperature):
21
- # Format message with the command-r chat template
22
  messages = [{"role": "user", "content": user_input}]
23
  input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
24
 
@@ -49,18 +48,23 @@ def setup_examples():
49
  with gr.Blocks() as demo:
50
  gr.Markdown(title)
51
  with gr.Row():
52
- message_box = gr.Textbox(lines=2, label="Your Message")
53
  max_new_tokens_slider = gr.Slider(minimum=10, maximum=100, value=50, label="Max New Tokens")
54
  temperature_slider = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.3, label="Temperature")
 
55
  generate_button = gr.Button("Try🫡Command-R")
56
  output_box = gr.Textbox(label="🫡Command-R")
57
-
 
 
 
 
 
 
 
 
58
  generate_button.click(
59
  fn=generate_response,
60
  inputs=[message_box, max_new_tokens_slider, temperature_slider],
61
  outputs=output_box
62
  )
63
- setup_examples_button = gr.Button("Load Example")
64
- setup_examples_button.click(fn=setup_examples, inputs=[], outputs=[])
65
-
66
- demo.launch()
 
18
 
19
  @spaces.GPU
20
  def generate_response(user_input, max_new_tokens, temperature):
 
21
  messages = [{"role": "user", "content": user_input}]
22
  input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
23
 
 
48
  with gr.Blocks() as demo:
49
  gr.Markdown(title)
50
  with gr.Row():
 
51
  max_new_tokens_slider = gr.Slider(minimum=10, maximum=100, value=50, label="Max New Tokens")
52
  temperature_slider = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.3, label="Temperature")
53
+ message_box = gr.Textbox(lines=2, label="Your Message")
54
  generate_button = gr.Button("Try🫡Command-R")
55
  output_box = gr.Textbox(label="🫡Command-R")
56
+ with gr.Accordion("🫡Examples", open=False):
57
+ gr.Examples(
58
+ examples=examples,
59
+ inputs=[message_box, max_new_tokens_slider, temperature_slider],
60
+ outputs=output_box,
61
+ fn=generate_response,
62
+ cache_examples=True
63
+ )
64
+
65
  generate_button.click(
66
  fn=generate_response,
67
  inputs=[message_box, max_new_tokens_slider, temperature_slider],
68
  outputs=output_box
69
  )
70
+ demo.launch()