alex-remade commited on
Commit
bd0b7e3
·
1 Parent(s): ad4ca82

working with both options

Browse files
Files changed (1) hide show
  1. app.py +54 -48
app.py CHANGED
@@ -80,6 +80,7 @@ loras = [
80
 
81
 
82
 
 
83
  ]
84
 
85
  # Initialize Supabase client with async support
@@ -256,8 +257,13 @@ async def generate_video(input_image, subject, duration, selected_index, progres
256
  workflow_path=str(WORKFLOW_PATH)
257
  )
258
 
259
- # Upload image to GCS and get public URL
260
- image_url = upload_to_gcs(input_image)
 
 
 
 
 
261
 
262
  # Map duration selection to actual seconds
263
  duration_mapping = {
@@ -336,45 +342,13 @@ def update_selection(evt: gr.SelectData):
336
  sentence = f"Selected LoRA: {selected_lora['title']}"
337
  return selected_lora['id'], sentence
338
 
339
- def select_example_image(evt: gr.SelectData):
340
- """Handle example image selection and return image URL and description"""
341
- example_images = [
342
- {
343
- "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_1c2c6e4c-8938-4464-9355-84508bcca24e.jpg",
344
- "description": "Old man"
345
- },
346
- {
347
- "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_1f2c6ec9-823f-46d2-982f-73c494e51877.jpg",
348
- "description": "Young woman"
349
- },
350
- {
351
- "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_24d949f0-8699-4714-9c82-854e1b963063.jpg",
352
- "description": "Puppy"
353
- },
354
- {
355
- "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_af26651e-be1a-40c0-be18-c42b3bf6d211.png",
356
- "description": "Mini toy dancers"
357
- },
358
- {
359
- "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_d22a894e-a074-4742-9e23-787f001a3184.jpg",
360
- "description": "Chair"
361
- },
362
- {
363
- "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_e6472106-4e9d-4620-b41b-a9bbe4893415.png",
364
- "description": "Cartoon boy on bike"
365
- }
366
- ]
367
-
368
- selected = example_images[evt.index]
369
- return selected["url"], selected["description"]
370
-
371
- async def handle_generation(input_image, subject, duration, selected_index, selected_example_url, progress=gr.Progress(track_tqdm=True)):
372
  try:
373
  if selected_index is None:
374
  raise gr.Error("You must select a LoRA before proceeding.")
375
 
376
  # Generate the video and get generation ID
377
- generation_id = await generate_video(input_image, subject, duration, selected_index)
378
 
379
  # Poll for status updates
380
  while True:
@@ -588,7 +562,6 @@ css = '''
588
  with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate", text_size="lg")) as demo:
589
  selected_index = gr.State(None)
590
  current_generation_id = gr.State(None)
591
- selected_example_url = gr.State(None)
592
 
593
  gr.Markdown("# Remade AI - Wan 2.1 I2V effects LoRAs ")
594
 
@@ -645,8 +618,8 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="
645
 
646
 
647
  with gr.Column(scale=1):
648
-
649
- input_image = gr.Image(type="filepath", label="")
650
 
651
  subject = gr.Textbox(label="Describe your subject", placeholder="Cat toy")
652
 
@@ -687,38 +660,71 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="
687
 
688
  progress_bar = gr.Markdown(elem_id="progress", visible=False)
689
  output = gr.Video(interactive=False, label="Output video")
690
-
691
-
692
 
693
  gallery.select(
694
  update_selection,
695
  outputs=[selected_index, selected_info]
696
  )
697
 
698
- # Connect example gallery selection to subject and selected_example_url
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
  example_gallery.select(
700
  fn=select_example_image,
701
- outputs=[selected_example_url, subject]
702
  )
703
 
704
  # Add a custom handler to check if inputs are valid
705
- def check_inputs(subject, input_image, selected_index, selected_example_url):
706
  if not selected_index:
707
  return gr.Error("You must select a LoRA before proceeding.")
708
  if not subject.strip():
709
  return gr.Error("Please describe your subject.")
710
- if input_image is None:
711
- return gr.Error("Please upload an image.")
712
  return None
713
 
714
  # Use gr.on for the button click with validation
715
  button.click(
716
  fn=check_inputs,
717
- inputs=[subject, input_image, selected_index, selected_example_url],
718
  outputs=None
719
  ).success(
720
  fn=handle_generation,
721
- inputs=[input_image, subject, duration, selected_index, selected_example_url],
722
  outputs=[output, current_generation_id, progress_bar]
723
  )
724
 
 
80
 
81
 
82
 
83
+
84
  ]
85
 
86
  # Initialize Supabase client with async support
 
257
  workflow_path=str(WORKFLOW_PATH)
258
  )
259
 
260
+ # Check if the input is a URL (example image) or a file path (user upload)
261
+ if input_image.startswith('http'):
262
+ # It's already a URL, use it directly
263
+ image_url = input_image
264
+ else:
265
+ # It's a file path, upload to GCS
266
+ image_url = upload_to_gcs(input_image)
267
 
268
  # Map duration selection to actual seconds
269
  duration_mapping = {
 
342
  sentence = f"Selected LoRA: {selected_lora['title']}"
343
  return selected_lora['id'], sentence
344
 
345
+ async def handle_generation(image_input, subject, duration, selected_index, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  try:
347
  if selected_index is None:
348
  raise gr.Error("You must select a LoRA before proceeding.")
349
 
350
  # Generate the video and get generation ID
351
+ generation_id = await generate_video(image_input, subject, duration, selected_index)
352
 
353
  # Poll for status updates
354
  while True:
 
562
  with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate", text_size="lg")) as demo:
563
  selected_index = gr.State(None)
564
  current_generation_id = gr.State(None)
 
565
 
566
  gr.Markdown("# Remade AI - Wan 2.1 I2V effects LoRAs ")
567
 
 
618
 
619
 
620
  with gr.Column(scale=1):
621
+ # Single image input component that will be used for both uploaded and example images
622
+ image_input = gr.Image(type="filepath", label="")
623
 
624
  subject = gr.Textbox(label="Describe your subject", placeholder="Cat toy")
625
 
 
660
 
661
  progress_bar = gr.Markdown(elem_id="progress", visible=False)
662
  output = gr.Video(interactive=False, label="Output video")
 
 
663
 
664
  gallery.select(
665
  update_selection,
666
  outputs=[selected_index, selected_info]
667
  )
668
 
669
+ # Modified function to handle example image selection
670
+ def select_example_image(evt: gr.SelectData):
671
+ """Handle example image selection and return image URL, description, and update image source"""
672
+ example_images = [
673
+ {
674
+ "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_1c2c6e4c-8938-4464-9355-84508bcca24e.jpg",
675
+ "description": "Old man"
676
+ },
677
+ {
678
+ "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_1f2c6ec9-823f-46d2-982f-73c494e51877.jpg",
679
+ "description": "Young woman"
680
+ },
681
+ {
682
+ "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_24d949f0-8699-4714-9c82-854e1b963063.jpg",
683
+ "description": "Puppy"
684
+ },
685
+ {
686
+ "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_af26651e-be1a-40c0-be18-c42b3bf6d211.png",
687
+ "description": "Mini toy dancers"
688
+ },
689
+ {
690
+ "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_d22a894e-a074-4742-9e23-787f001a3184.jpg",
691
+ "description": "Chair"
692
+ },
693
+ {
694
+ "url": "https://storage.googleapis.com/remade-v2/huggingface_assets/uploads_e6472106-4e9d-4620-b41b-a9bbe4893415.png",
695
+ "description": "Cartoon boy on bike"
696
+ }
697
+ ]
698
+
699
+ selected = example_images[evt.index]
700
+
701
+ # Return the URL, description, and update image source to "example"
702
+ return selected["url"], selected["description"], "example"
703
+
704
+ # Connect example gallery selection to image_input and subject
705
  example_gallery.select(
706
  fn=select_example_image,
707
+ outputs=[image_input, subject]
708
  )
709
 
710
  # Add a custom handler to check if inputs are valid
711
+ def check_inputs(subject, image_input, selected_index):
712
  if not selected_index:
713
  return gr.Error("You must select a LoRA before proceeding.")
714
  if not subject.strip():
715
  return gr.Error("Please describe your subject.")
716
+ if image_input is None:
717
+ return gr.Error("Please upload an image or select an example image.")
718
  return None
719
 
720
  # Use gr.on for the button click with validation
721
  button.click(
722
  fn=check_inputs,
723
+ inputs=[subject, image_input, selected_index],
724
  outputs=None
725
  ).success(
726
  fn=handle_generation,
727
+ inputs=[image_input, subject, duration, selected_index],
728
  outputs=[output, current_generation_id, progress_bar]
729
  )
730