Spaces:
Sleeping
Sleeping
envs
Browse files- helpers.py +41 -40
helpers.py
CHANGED
@@ -253,52 +253,53 @@ class Examples:
|
|
253 |
self.cache_examples = cache_examples
|
254 |
self.run_on_click = run_on_click
|
255 |
|
256 |
-
async def load_example(self, example_id):
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
|
267 |
|
268 |
def create(self) -> None:
|
269 |
"""Caches the examples if self.cache_examples is True and creates the Dataset
|
270 |
component to hold the examples"""
|
271 |
|
272 |
-
if Context.root_block:
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
if self.cache_examples:
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
|
|
302 |
|
303 |
async def cache(self) -> None:
|
304 |
"""
|
|
|
253 |
self.cache_examples = cache_examples
|
254 |
self.run_on_click = run_on_click
|
255 |
|
256 |
+
# async def load_example(self, example_id):
|
257 |
+
# processed_example = self.non_none_processed_examples[example_id]
|
258 |
+
# if len(self.inputs_with_examples) == 1:
|
259 |
+
# return update(
|
260 |
+
# value=processed_example[0], **self.dataset.component_props[0]
|
261 |
+
# )
|
262 |
+
# return [
|
263 |
+
# update(value=processed_example[i], **self.dataset.component_props[i])
|
264 |
+
# for i in range(len(self.inputs_with_examples))
|
265 |
+
# ]
|
266 |
|
267 |
|
268 |
def create(self) -> None:
|
269 |
"""Caches the examples if self.cache_examples is True and creates the Dataset
|
270 |
component to hold the examples"""
|
271 |
|
272 |
+
# if Context.root_block:
|
273 |
+
# self.load_input_event = self.dataset.click(
|
274 |
+
# self.load_example,
|
275 |
+
# inputs=[self.dataset],
|
276 |
+
# outputs=self.inputs_with_examples, # type: ignore
|
277 |
+
# show_progress="hidden",
|
278 |
+
# postprocess=False,
|
279 |
+
# queue=False,
|
280 |
+
# api_name=self.api_name, # type: ignore
|
281 |
+
# )
|
282 |
+
# if self.run_on_click and not self.cache_examples:
|
283 |
+
# if self.fn is None:
|
284 |
+
# raise ValueError("Cannot run_on_click if no function is provided")
|
285 |
+
# self.load_input_event.then(
|
286 |
+
# self.fn,
|
287 |
+
# inputs=self.inputs, # type: ignore
|
288 |
+
# outputs=self.outputs, # type: ignore
|
289 |
+
# )
|
290 |
+
|
291 |
+
# if self.cache_examples:
|
292 |
+
# if wasm_utils.IS_WASM:
|
293 |
+
# # In the Wasm mode, the `threading` module is not supported,
|
294 |
+
# # so `client_utils.synchronize_async` is also not available.
|
295 |
+
# # And `self.cache()` should be waited for to complete before this method returns,
|
296 |
+
# # (otherwise, an error "Cannot cache examples if not in a Blocks context" will be raised anyway)
|
297 |
+
# # so `eventloop.create_task(self.cache())` is also not an option.
|
298 |
+
# raise wasm_utils.WasmUnsupportedError(
|
299 |
+
# "Caching examples is not supported in the Wasm mode."
|
300 |
+
# )
|
301 |
+
# client_utils.synchronize_async(self.cache)
|
302 |
+
pass
|
303 |
|
304 |
async def cache(self) -> None:
|
305 |
"""
|