Update app.py
Browse files
app.py
CHANGED
|
@@ -106,15 +106,16 @@ def get_ai_video(pil_image, prompt, style, cb=None):
|
|
| 106 |
# ββ Color Grading βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 107 |
def color_grade(frame, style):
|
| 108 |
f = frame.astype(np.float32)/255.
|
| 109 |
-
|
|
|
|
| 110 |
if style=="premium":
|
| 111 |
lum=0.299*f[:,:,0]+0.587*f[:,:,1]+0.114*f[:,:,2]
|
| 112 |
sh=np.clip(1.-lum*2.5,0,1)[:,:,None]
|
| 113 |
hi=np.clip((lum-.6)*2.5,0,1)[:,:,None]
|
| 114 |
-
f[:,:,0]+=(-0.
|
| 115 |
-
f[:,:,1]+=(0.
|
| 116 |
-
f[:,:,2]+=(0.
|
| 117 |
-
f
|
| 118 |
elif style=="energetic":
|
| 119 |
gray=0.299*f[:,:,0:1]+0.587*f[:,:,1:2]+0.114*f[:,:,2:3]
|
| 120 |
f=np.clip(gray+1.5*(f-gray),0,1); f=np.clip(f*1.12-.02,0,1)
|
|
@@ -127,10 +128,10 @@ def color_grade(frame, style):
|
|
| 127 |
return np.clip(f*255,0,255).astype(np.uint8)
|
| 128 |
|
| 129 |
# ββ Vignette ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 130 |
-
def vignette(frame, strength=0.
|
| 131 |
h,w=frame.shape[:2]; Y,X=np.ogrid[:h,:w]
|
| 132 |
-
dist=np.sqrt(((X-w/2)/(w/2*.
|
| 133 |
-
mask=np.clip(1.-strength*dist**
|
| 134 |
return np.clip(frame.astype(np.float32)*mask[:,:,None],0,255).astype(np.uint8)
|
| 135 |
|
| 136 |
# ββ 3D Perspective Warp ββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -403,9 +404,9 @@ def render_cinematic(
|
|
| 403 |
img=ImageEnhance.Color(img).enhance(1.15)
|
| 404 |
base=np.array(img.resize((BW,BH),Image.LANCZOS))
|
| 405 |
|
| 406 |
-
# Pre-build vignette
|
| 407 |
Y,X=np.ogrid[:TH,:TW]
|
| 408 |
-
vmask=np.clip(1.-0.
|
| 409 |
|
| 410 |
# Bokeh system
|
| 411 |
bokeh=BokehSystem(TW,TH,n=22,style=style) if add_bokeh else None
|
|
@@ -463,10 +464,10 @@ def render_cinematic(
|
|
| 463 |
|
| 464 |
frame=cv2.resize(base[y1:y2,x1:x2],(TW,TH),interpolation=cv2.INTER_LINEAR)
|
| 465 |
|
| 466 |
-
# 3D perspective warp
|
| 467 |
ry,rx=get_3d_angles(tg)
|
| 468 |
-
if abs(ry)>0.3: frame=warp_3d(frame,ry,"y")
|
| 469 |
-
if abs(rx)>0.2: frame=warp_3d(frame,rx,"x")
|
| 470 |
|
| 471 |
# Color grade
|
| 472 |
frame=color_grade(frame,style)
|
|
@@ -486,9 +487,9 @@ def render_cinematic(
|
|
| 486 |
# Cinematic bars
|
| 487 |
if add_bars: frame[:44,:]=0; frame[-44:,:]=0
|
| 488 |
|
| 489 |
-
# Fade
|
| 490 |
-
if tg<0.
|
| 491 |
-
elif tg>0.
|
| 492 |
else: alpha=1.
|
| 493 |
if alpha<1.: frame=np.clip(frame.astype(np.float32)*alpha,0,255).astype(np.uint8)
|
| 494 |
|
|
|
|
| 106 |
# ββ Color Grading βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 107 |
def color_grade(frame, style):
|
| 108 |
f = frame.astype(np.float32)/255.
|
| 109 |
+
# Gentle S-curve β lift mids slightly, don't crush blacks
|
| 110 |
+
f = np.clip(f + 0.08*f*(1-f)*(2*f-1)*(-1), 0, 1)
|
| 111 |
if style=="premium":
|
| 112 |
lum=0.299*f[:,:,0]+0.587*f[:,:,1]+0.114*f[:,:,2]
|
| 113 |
sh=np.clip(1.-lum*2.5,0,1)[:,:,None]
|
| 114 |
hi=np.clip((lum-.6)*2.5,0,1)[:,:,None]
|
| 115 |
+
f[:,:,0]+=(-0.02*sh[:,:,0]+0.03*hi[:,:,0])
|
| 116 |
+
f[:,:,1]+=(0.01*sh[:,:,0]+0.01*hi[:,:,0])
|
| 117 |
+
f[:,:,2]+=(0.03*sh[:,:,0]-0.02*hi[:,:,0])
|
| 118 |
+
f=np.clip(f*1.03, 0, 1)
|
| 119 |
elif style=="energetic":
|
| 120 |
gray=0.299*f[:,:,0:1]+0.587*f[:,:,1:2]+0.114*f[:,:,2:3]
|
| 121 |
f=np.clip(gray+1.5*(f-gray),0,1); f=np.clip(f*1.12-.02,0,1)
|
|
|
|
| 128 |
return np.clip(f*255,0,255).astype(np.uint8)
|
| 129 |
|
| 130 |
# ββ Vignette ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 131 |
+
def vignette(frame, strength=0.40):
|
| 132 |
h,w=frame.shape[:2]; Y,X=np.ogrid[:h,:w]
|
| 133 |
+
dist=np.sqrt(((X-w/2)/(w/2*.90))**2+((Y-h/2)/(h/2))**2)
|
| 134 |
+
mask=np.clip(1.-strength*dist**1.8,0,1)
|
| 135 |
return np.clip(frame.astype(np.float32)*mask[:,:,None],0,255).astype(np.uint8)
|
| 136 |
|
| 137 |
# ββ 3D Perspective Warp ββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 404 |
img=ImageEnhance.Color(img).enhance(1.15)
|
| 405 |
base=np.array(img.resize((BW,BH),Image.LANCZOS))
|
| 406 |
|
| 407 |
+
# Pre-build vignette β gentle, not crushing blacks
|
| 408 |
Y,X=np.ogrid[:TH,:TW]
|
| 409 |
+
vmask=np.clip(1.-0.40*(np.sqrt(((X-TW/2)/(TW/2*.90))**2+((Y-TH/2)/(TH/2))**2)**1.8),0,1).astype(np.float32)
|
| 410 |
|
| 411 |
# Bokeh system
|
| 412 |
bokeh=BokehSystem(TW,TH,n=22,style=style) if add_bokeh else None
|
|
|
|
| 464 |
|
| 465 |
frame=cv2.resize(base[y1:y2,x1:x2],(TW,TH),interpolation=cv2.INTER_LINEAR)
|
| 466 |
|
| 467 |
+
# 3D perspective warp β gentle angles only
|
| 468 |
ry,rx=get_3d_angles(tg)
|
| 469 |
+
if abs(ry)>0.3: frame=warp_3d(frame,ry*0.5,"y")
|
| 470 |
+
if abs(rx)>0.2: frame=warp_3d(frame,rx*0.5,"x")
|
| 471 |
|
| 472 |
# Color grade
|
| 473 |
frame=color_grade(frame,style)
|
|
|
|
| 487 |
# Cinematic bars
|
| 488 |
if add_bars: frame[:44,:]=0; frame[-44:,:]=0
|
| 489 |
|
| 490 |
+
# Fade β very quick fade in (first 3%), slow fade out
|
| 491 |
+
if tg<0.03: alpha=ease_out_expo(tg/0.03)
|
| 492 |
+
elif tg>0.93: alpha=ease_in_out((1.-tg)/0.07)
|
| 493 |
else: alpha=1.
|
| 494 |
if alpha<1.: frame=np.clip(frame.astype(np.float32)*alpha,0,255).astype(np.uint8)
|
| 495 |
|