hysts HF staff commited on
Commit
1827259
1 Parent(s): 2c5e3cb

Cache examples

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from typing import Iterator
2
 
3
  import gradio as gr
@@ -32,6 +33,7 @@ this demo is governed by the original [license](LICENSE.txt) and [acceptable use
32
  if not torch.cuda.is_available():
33
  DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
34
 
 
35
  def clear_and_save_textbox(message: str) -> tuple[str, str]:
36
  return '', message
37
 
@@ -75,6 +77,14 @@ def generate(
75
  yield history + [(message, response)]
76
 
77
 
 
 
 
 
 
 
 
 
78
  with gr.Blocks(css='style.css') as demo:
79
  gr.Markdown(DESCRIPTION)
80
  gr.DuplicateButton(value='Duplicate Space for private use',
@@ -134,16 +144,19 @@ with gr.Blocks(css='style.css') as demo:
134
  )
135
 
136
  gr.Examples(
137
- examples = [
138
- ["Hello there! How are you doing?"],
139
- ["Can you explain to me briefly what is Python programming language?"],
140
- ["Explain the plot of Cinderella in a sentence."],
141
- ["How many hours does it take a man to eat a Helicopter?"],
142
- ["Write a 100-word article on 'Benefits of Open-Source in AI research'"]
143
- ],
144
- inputs = textbox,
145
- label = "Click on any example and press the 'Submit' button",
 
 
146
  )
 
147
  gr.Markdown(LICENSE)
148
 
149
  textbox.submit(
 
1
+ import os
2
  from typing import Iterator
3
 
4
  import gradio as gr
 
33
  if not torch.cuda.is_available():
34
  DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
35
 
36
+
37
  def clear_and_save_textbox(message: str) -> tuple[str, str]:
38
  return '', message
39
 
 
77
  yield history + [(message, response)]
78
 
79
 
80
+ def process_example(message: str) -> tuple[str, list[tuple[str, str]]]:
81
+ generator = generate(message, [], DEFAULT_SYSTEM_PROMPT, 1024, 0.95, 1,
82
+ 1000)
83
+ for x in generator:
84
+ pass
85
+ return '', x
86
+
87
+
88
  with gr.Blocks(css='style.css') as demo:
89
  gr.Markdown(DESCRIPTION)
90
  gr.DuplicateButton(value='Duplicate Space for private use',
 
144
  )
145
 
146
  gr.Examples(
147
+ examples=[
148
+ 'Hello there! How are you doing?',
149
+ 'Can you explain to me briefly what is Python programming language?',
150
+ 'Explain the plot of Cinderella in a sentence.',
151
+ 'How many hours does it take a man to eat a Helicopter?',
152
+ "Write a 100-word article on 'Benefits of Open-Source in AI research'",
153
+ ],
154
+ inputs=textbox,
155
+ outputs=[textbox, chatbot],
156
+ fn=process_example,
157
+ cache_examples=os.getenv('CACHE_EXAMPLES') == '1',
158
  )
159
+
160
  gr.Markdown(LICENSE)
161
 
162
  textbox.submit(