davidpie-1 commited on
Commit
a59cdb5
·
verified ·
1 Parent(s): 4e08519

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -9
app.py CHANGED
@@ -1,27 +1,53 @@
1
  import gradio as gr
2
  from PIL import Image
3
  from rembg import remove
4
- import spaces # <--- This fixes the GPU error
 
5
 
6
- @spaces.GPU # <--- Tells Hugging Face we are using the free processor
7
- def process_image(image):
8
  if image is None:
9
- return None
 
 
10
  original_img = image.convert("RGB")
11
  cutout = remove(original_img)
12
- return cutout
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  with gr.Blocks(title="AdSpin Studio") as demo:
15
  gr.Markdown("# 🛍️ AdSpin Studio")
16
- gr.Markdown("Upload a product photo. We will isolate the product (The Moat) so the video AI doesn't morph it.")
17
 
18
  with gr.Row():
19
  with gr.Column():
20
  input_img = gr.Image(type="pil", label="Upload Product Photo")
21
- generate_btn = gr.Button("Isolate Product", variant="primary")
22
  with gr.Column():
23
- output_img = gr.Image(label="Product Isolated", type="pil")
 
24
 
25
- generate_btn.click(fn=process_image, inputs=input_img, outputs=output_img)
26
 
27
  demo.launch()
 
1
  import gradio as gr
2
  from PIL import Image
3
  from rembg import remove
4
+ import spaces
5
+ from gradio_client import Client, handle_file
6
 
7
+ @spaces.GPU
8
+ def process_and_generate(image):
9
  if image is None:
10
+ return None, None
11
+
12
+ # Step 1: Isolate Product (The Moat)
13
  original_img = image.convert("RGB")
14
  cutout = remove(original_img)
15
+
16
+ # Step 2: Send to Free Wan 2.1 API
17
+ try:
18
+ # We use a public free Wan 2.1 Space as our backend GPU
19
+ client = Client("Wan-AI/Wan2.1-I2V-14B-480P")
20
+
21
+ # Save cutout temporarily to send to API
22
+ temp_path = "temp_cutout.png"
23
+ cutout.save(temp_path)
24
+
25
+ # Generate Video
26
+ result = client.predict(
27
+ image=handle_file(temp_path),
28
+ prompt="product rotating slowly 360 degrees on a turntable, studio lighting, seamless white background, smooth constant rotation, no morphing",
29
+ api_name="/generate"
30
+ )
31
+
32
+ video_path = result
33
+ return cutout, video_path
34
+
35
+ except Exception as e:
36
+ print(f"Error: {e}")
37
+ return cutout, "GPU is busy. Please try again in 30 seconds."
38
 
39
  with gr.Blocks(title="AdSpin Studio") as demo:
40
  gr.Markdown("# 🛍️ AdSpin Studio")
41
+ gr.Markdown("Upload a product photo. We isolate it, then Wan 2.1 animates it.")
42
 
43
  with gr.Row():
44
  with gr.Column():
45
  input_img = gr.Image(type="pil", label="Upload Product Photo")
46
+ generate_btn = gr.Button("Generate Video Ad", variant="primary")
47
  with gr.Column():
48
+ output_img = gr.Image(label="1. Product Isolated", type="pil")
49
+ output_vid = gr.Video(label="2. Final Video Ad")
50
 
51
+ generate_btn.click(fn=process_and_generate, inputs=input_img, outputs=[output_img, output_vid])
52
 
53
  demo.launch()