LipKit commited on
Commit
e1c844f
Β·
1 Parent(s): 30ca3fe

Deploy LipKit v1.0 - Free AI Lip Sync Studio

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-314.pyc +0 -0
  2. app.py +19 -15
__pycache__/app.cpython-314.pyc CHANGED
Binary files a/__pycache__/app.cpython-314.pyc and b/__pycache__/app.cpython-314.pyc differ
 
app.py CHANGED
@@ -200,15 +200,15 @@ def lipkit_generate(video_file, voice_file, script, use_voice_clone, language, p
200
  return output_path, f"Done! {voice_note}"
201
 
202
  # ── IVM Function ──────────────────────────────────────────────────────────────
203
- def ivm_generate(dress_image, model_image, blur_face, make_video, progress=gr.Progress()):
 
204
  if dress_image is None: raise gr.Error("Please upload a dress photo.")
205
  progress(0.1, desc="Processing images...")
206
- from PIL import Image, ImageFilter
207
  import uuid
208
  base = f"ivm_{uuid.uuid4().hex[:8]}"
209
  dress_img = Image.open(dress_image).convert("RGB").resize((512, 512), Image.LANCZOS)
210
- dress_path = str(IVM_DIR / f"{base}_dress.png"); Image.open(dress_path).save(dress_path) # noqa
211
- dress_img.save(dress_path)
212
  model_path = dress_path
213
  if model_image is not None:
214
  m = Image.open(model_image).convert("RGB").resize((512, 512), Image.LANCZOS)
@@ -223,26 +223,31 @@ def ivm_generate(dress_image, model_image, blur_face, make_video, progress=gr.Pr
223
  except Exception as e: print(f"[IVM] OOTDiffusion failed: {e}")
224
  out_img = str(IVM_DIR / f"{base}_result.png")
225
  shutil.copy2(result_path, out_img)
226
- if blur_face:
227
- progress(0.8, desc="Blurring face...")
228
- img = Image.open(out_img).convert("RGB")
229
- w, h = img.size
230
- img.paste(img.crop((w//4,0,w*3//4,h//3)).filter(ImageFilter.GaussianBlur(25)), (w//4,0))
231
- img.save(out_img)
 
232
  progress(0.9, desc="Done!")
233
  video_path = None
234
  if make_video:
235
- progress(0.85, desc="Generating video...")
236
  try:
237
  v = Client("stabilityai/stable-video-diffusion-img2vid", timeout=120).predict(
238
  out_img, "Auto", 25, -1, 2.5, "SVD", api_name="/predict")
239
  if v and len(v) > 0 and v[0] and os.path.isfile(v[0]):
240
  video_path = str(IVM_DIR / f"{base}_video.mp4"); shutil.copy2(v[0], video_path)
 
 
 
 
241
  except Exception as e: print(f"[IVM] SVD failed: {e}")
242
  save_to_history({
243
  "type": "ivm", "time": time.strftime("%Y-%m-%d %H:%M"),
244
  "image_path": out_img, "video_path": video_path,
245
- "has_video": video_path is not None, "blurred": blur_face,
246
  })
247
  return out_img, video_path
248
 
@@ -293,7 +298,7 @@ def refresh_ivm_history():
293
  <div style="background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.06);border-radius:12px;padding:16px;overflow:hidden">
294
  <img src="/file={h['image_path']}" style="width:100%;height:200px;object-fit:contain;border-radius:8px;background:#000;margin-bottom:10px" />
295
  <div style="display:flex;justify-content:space-between;align-items:center">
296
- <span style="font-size:11px;color:#71717a">{h['time']}{' πŸ”΅ Face Blurred' if h.get('blurred') else ''}</span>
297
  <div style="display:flex;gap:8px">
298
  <a href="/file={h['image_path']}" download style="font-size:12px;color:#a855f7;text-decoration:none;font-weight:600">⬇ Image</a>
299
  {f'<a href="/file={h["video_path"]}" download style="font-size:12px;color:#06b6d4;text-decoration:none;font-weight:600">🎬 Video</a>' if has_vid else ''}
@@ -374,7 +379,6 @@ with gr.Blocks(title="VoiceKit Studio", css=CSS, theme=gr.themes.Soft(primary_hu
374
  ivm_model = gr.Image(label="Model Photo (optional)", type="filepath", sources=["upload"])
375
 
376
  with gr.Row():
377
- ivm_blur = gr.Checkbox(label="Blur face", value=True)
378
  ivm_video = gr.Checkbox(label="Generate looping video (+2 min)", value=False)
379
 
380
  ivm_btn = gr.Button("🧠 Generate IVM", variant="primary", size="lg")
@@ -383,7 +387,7 @@ with gr.Blocks(title="VoiceKit Studio", css=CSS, theme=gr.themes.Soft(primary_hu
383
  ivm_img_out = gr.Image(label="Dress on Model", type="filepath")
384
  ivm_vid_out = gr.Video(label="Looping Video")
385
 
386
- ivm_btn.click(fn=ivm_generate, inputs=[ivm_dress, ivm_model, ivm_blur, ivm_video], outputs=[ivm_img_out, ivm_vid_out])
387
 
388
  gr.Markdown("### Previously Generated Images")
389
  ivm_history_html = gr.HTML(value=refresh_ivm_history())
 
200
  return output_path, f"Done! {voice_note}"
201
 
202
  # ── IVM Function ──────────────────────────────────────────────────────────────
203
+ def ivm_generate(dress_image, model_image, make_video, progress=gr.Progress()):
204
+ """IVM β€” Body-only view, face hidden by cropping top 30%."""
205
  if dress_image is None: raise gr.Error("Please upload a dress photo.")
206
  progress(0.1, desc="Processing images...")
207
+ from PIL import Image
208
  import uuid
209
  base = f"ivm_{uuid.uuid4().hex[:8]}"
210
  dress_img = Image.open(dress_image).convert("RGB").resize((512, 512), Image.LANCZOS)
211
+ dress_path = str(IVM_DIR / f"{base}_dress.png"); dress_img.save(dress_path)
 
212
  model_path = dress_path
213
  if model_image is not None:
214
  m = Image.open(model_image).convert("RGB").resize((512, 512), Image.LANCZOS)
 
223
  except Exception as e: print(f"[IVM] OOTDiffusion failed: {e}")
224
  out_img = str(IVM_DIR / f"{base}_result.png")
225
  shutil.copy2(result_path, out_img)
226
+
227
+ # Crop top 30% off to hide face
228
+ progress(0.7, desc="Cropping to body-only view...")
229
+ img = Image.open(out_img).convert("RGB")
230
+ w, h = img.size
231
+ img.crop((0, int(h * 0.30), w, h)).save(out_img)
232
+
233
  progress(0.9, desc="Done!")
234
  video_path = None
235
  if make_video:
236
+ progress(0.85, desc="Generating body-only video...")
237
  try:
238
  v = Client("stabilityai/stable-video-diffusion-img2vid", timeout=120).predict(
239
  out_img, "Auto", 25, -1, 2.5, "SVD", api_name="/predict")
240
  if v and len(v) > 0 and v[0] and os.path.isfile(v[0]):
241
  video_path = str(IVM_DIR / f"{base}_video.mp4"); shutil.copy2(v[0], video_path)
242
+ cropped = str(IVM_DIR / f"{base}_body.mp4")
243
+ subprocess.run(["ffmpeg", "-i", video_path, "-vf", "crop=iw:ih*0.7:0:ih*0.3", cropped],
244
+ capture_output=True, timeout=30)
245
+ if os.path.isfile(cropped): video_path = cropped
246
  except Exception as e: print(f"[IVM] SVD failed: {e}")
247
  save_to_history({
248
  "type": "ivm", "time": time.strftime("%Y-%m-%d %H:%M"),
249
  "image_path": out_img, "video_path": video_path,
250
+ "has_video": video_path is not None, "body_only": True,
251
  })
252
  return out_img, video_path
253
 
 
298
  <div style="background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.06);border-radius:12px;padding:16px;overflow:hidden">
299
  <img src="/file={h['image_path']}" style="width:100%;height:200px;object-fit:contain;border-radius:8px;background:#000;margin-bottom:10px" />
300
  <div style="display:flex;justify-content:space-between;align-items:center">
301
+ <span style="font-size:11px;color:#71717a">{h['time']}{' πŸ”΅ Body Only' if h.get('body_only') else ''}</span>
302
  <div style="display:flex;gap:8px">
303
  <a href="/file={h['image_path']}" download style="font-size:12px;color:#a855f7;text-decoration:none;font-weight:600">⬇ Image</a>
304
  {f'<a href="/file={h["video_path"]}" download style="font-size:12px;color:#06b6d4;text-decoration:none;font-weight:600">🎬 Video</a>' if has_vid else ''}
 
379
  ivm_model = gr.Image(label="Model Photo (optional)", type="filepath", sources=["upload"])
380
 
381
  with gr.Row():
 
382
  ivm_video = gr.Checkbox(label="Generate looping video (+2 min)", value=False)
383
 
384
  ivm_btn = gr.Button("🧠 Generate IVM", variant="primary", size="lg")
 
387
  ivm_img_out = gr.Image(label="Dress on Model", type="filepath")
388
  ivm_vid_out = gr.Video(label="Looping Video")
389
 
390
+ ivm_btn.click(fn=ivm_generate, inputs=[ivm_dress, ivm_model, ivm_video], outputs=[ivm_img_out, ivm_vid_out])
391
 
392
  gr.Markdown("### Previously Generated Images")
393
  ivm_history_html = gr.HTML(value=refresh_ivm_history())