ford442 commited on
Commit
b4c9d0b
·
1 Parent(s): e7981bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -162,13 +162,10 @@ GPU_DURATION_OPTIONS = {
162
  "Long (140s)": 140,
163
  }
164
 
165
- # Set the default GPU duration here
166
- DEFAULT_DURATION_CHOICE = "Medium (60s)"
167
 
168
- # Set the GPU duration environment variable
169
- os.environ["GPU_DURATION"] = str(GPU_DURATION_OPTIONS[DEFAULT_DURATION_CHOICE])
170
-
171
- @spaces.GPU(duration=int(os.getenv("GPU_DURATION"))) # Dynamic duration
172
  def generate(
173
  model_choice: str,
174
  prompt: str,
@@ -273,7 +270,7 @@ def generate_cpu(
273
  return image_paths, seed
274
 
275
  def set_gpu_duration(duration_choice):
276
- os.environ["GPU_DURATION"] = str(GPU_DURATION_OPTIONS[duration_choice])
277
 
278
  def load_predefined_images1():
279
  predefined_images1 = [
@@ -327,13 +324,18 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
327
  )
328
 
329
  with gr.Accordion("Advanced options", open=False, visible=True):
330
- gpu_duration = gr.Dropdown(
331
- label="GPU Duration",
332
- choices=list(GPU_DURATION_OPTIONS.keys()),
333
- value="Medium (60s)" # Default value
 
 
 
 
 
334
  )
335
 
336
- gpu_duration.change(fn=set_gpu_duration, inputs=gpu_duration, outputs=[])
337
 
338
  style_selection = gr.Radio(
339
  show_label=True,
 
162
  "Long (140s)": 140,
163
  }
164
 
165
+ # Initialize Gradio state
166
+ gpu_duration_state = gr.State(60) # Initial value
167
 
168
+ @spaces.GPU(duration=gpu_duration_state.value) # Access state value
 
 
 
169
  def generate(
170
  model_choice: str,
171
  prompt: str,
 
270
  return image_paths, seed
271
 
272
  def set_gpu_duration(duration_choice):
273
+ return GPU_DURATION_OPTIONS[duration_choice] # Update state
274
 
275
  def load_predefined_images1():
276
  predefined_images1 = [
 
324
  )
325
 
326
  with gr.Accordion("Advanced options", open=False, visible=True):
327
+ duration_dropdown = gr.Dropdown(
328
+ choices=[
329
+ "Short (25s)",
330
+ "Short (45s)",
331
+ "Medium (60s)",
332
+ "Medium (80s)",
333
+ "Long (100s)",
334
+ "Long (120s)",
335
+ "Long (140s)",
336
  )
337
 
338
+ duration_dropdown.change(set_gpu_duration, inputs=duration_dropdown, outputs=gpu_duration_state)
339
 
340
  style_selection = gr.Radio(
341
  show_label=True,