ford442 commited on
Commit
b1ad971
·
1 Parent(s): fef75b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -162,10 +162,10 @@ GPU_DURATION_OPTIONS = {
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,7 +270,8 @@ def generate_cpu(
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,19 +325,13 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
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
 
339
- duration_dropdown.change(set_gpu_duration, inputs=duration_dropdown, outputs=gpu_duration_state)
340
 
341
  style_selection = gr.Radio(
342
  show_label=True,
 
162
  "Long (140s)": 140,
163
  }
164
 
165
+ # Global variable to store GPU duration
166
+ global_gpu_duration = 60 # Initial value
167
 
168
+ @spaces.GPU(duration=global_gpu_duration)
169
  def generate(
170
  model_choice: str,
171
  prompt: str,
 
270
  return image_paths, seed
271
 
272
  def set_gpu_duration(duration_choice):
273
+ global global_gpu_duration
274
+ global_gpu_duration = GPU_DURATION_OPTIONS[duration_choice]
275
 
276
  def load_predefined_images1():
277
  predefined_images1 = [
 
325
  )
326
 
327
  with gr.Accordion("Advanced options", open=False, visible=True):
328
+ gpu_duration = gr.Dropdown(
329
+ label="GPU Duration",
330
+ choices=list(GPU_DURATION_OPTIONS.keys()),
331
+ value="Medium (60s)" # Default value
 
 
 
 
 
 
332
  )
333
 
334
+ gpu_duration.change(fn=set_gpu_duration, inputs=gpu_duration, outputs=[])
335
 
336
  style_selection = gr.Radio(
337
  show_label=True,