celinah HF Staff commited on
Commit
3a09df2
·
1 Parent(s): 2730363
Files changed (1) hide show
  1. app.py +7 -22
app.py CHANGED
@@ -65,8 +65,7 @@ def login(oauth_token: gr.OAuthToken | None):
65
  else:
66
  if not TOKEN:
67
  print("No Hugging Face OAuth token received and HF_TOKEN environment variable not set.")
68
- gr.Warning("Hugging Face token not set. Image generation via HF Inference Providers might fail.")
69
- else: # It was already set, and no new OAuth token, so it's still configured
70
  gr.Info("Hugging Face token remains configured (no new OAuth token).")
71
 
72
  if oauth_token is None:
@@ -94,15 +93,12 @@ def set_fal_key(fal_key_from_ui: str | None):
94
  env_fal_key = os.environ.get("FAL_KEY")
95
  if env_fal_key:
96
  FAL_KEY = env_fal_key
97
- print("FAL_KEY UI input empty, using key from environment variable.")
98
  gr.Info("FAL_KEY is configured from environment variable (UI input was empty).")
99
  else:
100
  FAL_KEY = None
101
  print("FAL_KEY UI input empty and not found in environment. FAL_KEY is now unset.")
102
- gr.Warning("FAL_KEY is not set. Video generation will not work.")
103
  elif not FAL_KEY:
104
  print("FAL_KEY not provided in UI and not in environment.")
105
- gr.Warning("FAL_KEY not set. Video generation will not work.")
106
  else:
107
  gr.Info("FAL_KEY is configured.")
108
 
@@ -224,6 +220,7 @@ css = """
224
 
225
  with gr.Blocks(css=css) as demo:
226
  demo.load(login, inputs=None, outputs=None)
 
227
  with gr.Sidebar():
228
  gr.Markdown("# Authentication")
229
  gr.Markdown(
@@ -323,7 +320,7 @@ with gr.Blocks(css=css) as demo:
323
  inputs=[prompt, seed_slider, width_slider, height_slider, steps_slider],
324
  outputs=[result, seed_number],
325
  ).then(
326
- lambda img_path, vid_accordion, vid_btn: { # Make video section interactive
327
  vid_accordion: gr.Accordion(open=True),
328
  vid_btn: gr.Button(interactive=True),
329
  },
@@ -355,21 +352,14 @@ with gr.Blocks(css=css) as demo:
355
  minimum=0.0,
356
  maximum=10.0,
357
  value=0.5,
358
- step=0.1, # Default from API (0.5 seems low, API docs mention it, let's check if it's a typo or specific to this model)
359
  )
360
  generate_video_btn = gr.Button("Generate Video", interactive=False)
361
 
362
- # Update the run_button.click().then() to target these video components
363
- # We need to define them first, so I'm moving the .then() part of run_button here.
364
- # This is a bit tricky with Gradio's sequential definition. Let's re-organize slightly.
365
-
366
- # The previous run_button.click had a .then() that needs video_gen_accordion and generate_video_btn
367
- # We'll chain it properly after these are defined.
368
-
369
  generate_video_btn.click(
370
  fn=generate_video_from_image,
371
  inputs=[
372
- result, # This is the gr.Image component, its output (filepath) will be passed
373
  video_prompt_input,
374
  video_duration_input,
375
  video_aspect_ratio_input,
@@ -379,22 +369,17 @@ with gr.Blocks(css=css) as demo:
379
  outputs=[video_result_output],
380
  )
381
 
382
- # Now, correctly chain the .then() for the image generation button
383
  run_button.click(
384
  fn=generate,
385
  inputs=[prompt, seed_slider, width_slider, height_slider, steps_slider],
386
  outputs=[result, seed_number],
387
  ).then(
388
- # This function will run after 'generate' and will update the UI
389
- # It receives the outputs of 'generate' as its inputs.
390
- # We use `result` (the gr.Image component's output which is a filepath)
391
- # to enable the video section.
392
- lambda image_filepath: { # image_filepath will be the path from the `result` gr.Image
393
  video_gen_accordion: gr.Accordion(open=True),
394
  generate_video_btn: gr.Button(interactive=True if image_filepath else False),
395
  download_btn: gr.DownloadButton(value=image_filepath, visible=True if image_filepath else False),
396
  },
397
- inputs=[result], # Input to this lambda is the output of `result` (gr.Image)
398
  outputs=[video_gen_accordion, generate_video_btn, download_btn],
399
  )
400
  with gr.Accordion("Download Image from URL", open=False):
 
65
  else:
66
  if not TOKEN:
67
  print("No Hugging Face OAuth token received and HF_TOKEN environment variable not set.")
68
+ else:
 
69
  gr.Info("Hugging Face token remains configured (no new OAuth token).")
70
 
71
  if oauth_token is None:
 
93
  env_fal_key = os.environ.get("FAL_KEY")
94
  if env_fal_key:
95
  FAL_KEY = env_fal_key
 
96
  gr.Info("FAL_KEY is configured from environment variable (UI input was empty).")
97
  else:
98
  FAL_KEY = None
99
  print("FAL_KEY UI input empty and not found in environment. FAL_KEY is now unset.")
 
100
  elif not FAL_KEY:
101
  print("FAL_KEY not provided in UI and not in environment.")
 
102
  else:
103
  gr.Info("FAL_KEY is configured.")
104
 
 
220
 
221
  with gr.Blocks(css=css) as demo:
222
  demo.load(login, inputs=None, outputs=None)
223
+ demo.load(set_fal_key, inputs=None, outputs=None)
224
  with gr.Sidebar():
225
  gr.Markdown("# Authentication")
226
  gr.Markdown(
 
320
  inputs=[prompt, seed_slider, width_slider, height_slider, steps_slider],
321
  outputs=[result, seed_number],
322
  ).then(
323
+ lambda img_path, vid_accordion, vid_btn: {
324
  vid_accordion: gr.Accordion(open=True),
325
  vid_btn: gr.Button(interactive=True),
326
  },
 
352
  minimum=0.0,
353
  maximum=10.0,
354
  value=0.5,
355
+ step=0.1,
356
  )
357
  generate_video_btn = gr.Button("Generate Video", interactive=False)
358
 
 
 
 
 
 
 
 
359
  generate_video_btn.click(
360
  fn=generate_video_from_image,
361
  inputs=[
362
+ result,
363
  video_prompt_input,
364
  video_duration_input,
365
  video_aspect_ratio_input,
 
369
  outputs=[video_result_output],
370
  )
371
 
 
372
  run_button.click(
373
  fn=generate,
374
  inputs=[prompt, seed_slider, width_slider, height_slider, steps_slider],
375
  outputs=[result, seed_number],
376
  ).then(
377
+ lambda image_filepath: {
 
 
 
 
378
  video_gen_accordion: gr.Accordion(open=True),
379
  generate_video_btn: gr.Button(interactive=True if image_filepath else False),
380
  download_btn: gr.DownloadButton(value=image_filepath, visible=True if image_filepath else False),
381
  },
382
+ inputs=[result],
383
  outputs=[video_gen_accordion, generate_video_btn, download_btn],
384
  )
385
  with gr.Accordion("Download Image from URL", open=False):