Tonic commited on
Commit
4f6966f
1 Parent(s): b5aae38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -33,7 +33,10 @@ def generate_response(user_input, max_new_tokens, temperature):
33
  gen_text = tokenizer.decode(gen_tokens[0])
34
  return gen_text
35
 
36
-
 
 
 
37
  examples = [
38
  {"message": "What is the weather like today?", "max_new_tokens": 250, "temperature": 0.5},
39
  {"message": "Tell me a joke.", "max_new_tokens": 650, "temperature": 0.7},
@@ -48,18 +51,17 @@ with gr.Blocks() as demo:
48
  message_box = gr.Textbox(lines=2, label="Your Message")
49
  generate_button = gr.Button("Try🫡Command-R")
50
  output_box = gr.Textbox(label="🫡Command-R")
51
- with gr.Accordion("🫡Examples", open=True):
52
- gr.Examples(
53
- examples=examples,
54
- inputs=[message_box, max_new_tokens_slider, temperature_slider],
55
- outputs=output_box,
56
- fn=generate_response,
57
- cache_examples=True
58
- )
59
 
60
  generate_button.click(
61
  fn=generate_response,
62
  inputs=[message_box, max_new_tokens_slider, temperature_slider],
63
  outputs=output_box
64
  )
 
 
 
 
 
 
 
65
  demo.launch()
 
33
  gen_text = tokenizer.decode(gen_tokens[0])
34
  return gen_text
35
 
36
+ def load_example(example_index):
37
+ example = examples[example_index]
38
+ return example
39
+
40
  examples = [
41
  {"message": "What is the weather like today?", "max_new_tokens": 250, "temperature": 0.5},
42
  {"message": "Tell me a joke.", "max_new_tokens": 650, "temperature": 0.7},
 
51
  message_box = gr.Textbox(lines=2, label="Your Message")
52
  generate_button = gr.Button("Try🫡Command-R")
53
  output_box = gr.Textbox(label="🫡Command-R")
 
 
 
 
 
 
 
 
54
 
55
  generate_button.click(
56
  fn=generate_response,
57
  inputs=[message_box, max_new_tokens_slider, temperature_slider],
58
  outputs=output_box
59
  )
60
+ example_dropdown = gr.Dropdown(label="Load Example", choices=[f"Example {i+1}" for i in range(len(examples))])
61
+ example_button = gr.Button("Load")
62
+ example_button.click(
63
+ fn=load_example,
64
+ inputs=example_dropdown,
65
+ outputs=[message_box, max_new_tokens_slider, temperature_slider]
66
+ )
67
  demo.launch()