Commit
·
e8a13e5
1
Parent(s):
85e29a3
add some drama
Browse files- utils/color_model.py +56 -10
utils/color_model.py
CHANGED
|
@@ -12,6 +12,10 @@ model_path = hf_hub_download(
|
|
| 12 |
model = tf.keras.models.load_model(model_path, compile=False)
|
| 13 |
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def infer_color(vad):
|
| 16 |
input_data = np.array([[
|
| 17 |
vad["V"],
|
|
@@ -22,26 +26,68 @@ def infer_color(vad):
|
|
| 22 |
]], dtype=np.float32)
|
| 23 |
|
| 24 |
output = model.predict(input_data, verbose=0)[0]
|
| 25 |
-
|
| 26 |
r, g, b, e, i = output
|
| 27 |
|
| 28 |
return {
|
| 29 |
"R": float(r),
|
| 30 |
"G": float(g),
|
| 31 |
"B": float(b),
|
| 32 |
-
"E": float(e),
|
| 33 |
-
"I": float(i)
|
| 34 |
}
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return {
|
| 38 |
-
"R": int(
|
| 39 |
-
"G": int(
|
| 40 |
-
"B": int(
|
| 41 |
-
"E":
|
| 42 |
-
"I":
|
| 43 |
}
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
def render_color(rgb):
|
| 46 |
return f"""
|
| 47 |
<div style="
|
|
@@ -50,7 +96,7 @@ def render_color(rgb):
|
|
| 50 |
border-radius:18px;
|
| 51 |
background: rgb({rgb['R']},{rgb['G']},{rgb['B']});
|
| 52 |
box-shadow: 0px 6px 32px rgba(0,0,0,0.25);
|
| 53 |
-
transition: all 0.
|
| 54 |
"></div>
|
| 55 |
"""
|
| 56 |
|
|
|
|
| 12 |
model = tf.keras.models.load_model(model_path, compile=False)
|
| 13 |
|
| 14 |
|
| 15 |
+
# -------------------------------------------------
|
| 16 |
+
# Model Inference
|
| 17 |
+
# -------------------------------------------------
|
| 18 |
+
|
| 19 |
def infer_color(vad):
|
| 20 |
input_data = np.array([[
|
| 21 |
vad["V"],
|
|
|
|
| 26 |
]], dtype=np.float32)
|
| 27 |
|
| 28 |
output = model.predict(input_data, verbose=0)[0]
|
|
|
|
| 29 |
r, g, b, e, i = output
|
| 30 |
|
| 31 |
return {
|
| 32 |
"R": float(r),
|
| 33 |
"G": float(g),
|
| 34 |
"B": float(b),
|
| 35 |
+
"E": float(e), # Energy
|
| 36 |
+
"I": float(i) # Intensity
|
| 37 |
}
|
| 38 |
|
| 39 |
+
|
| 40 |
+
# -------------------------------------------------
|
| 41 |
+
# Cinematic Drama Rendering
|
| 42 |
+
# -------------------------------------------------
|
| 43 |
+
|
| 44 |
+
def apply_cinematic_blend(model_output, drama):
|
| 45 |
+
"""
|
| 46 |
+
drama:
|
| 47 |
+
0.0 → near white
|
| 48 |
+
1.0 → cinematic target
|
| 49 |
+
1.5 → expressive peak
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
color = np.array([
|
| 53 |
+
model_output["R"],
|
| 54 |
+
model_output["G"],
|
| 55 |
+
model_output["B"]
|
| 56 |
+
])
|
| 57 |
+
|
| 58 |
+
energy = model_output["E"]
|
| 59 |
+
intensity = model_output["I"]
|
| 60 |
+
|
| 61 |
+
white = np.array([1.0, 1.0, 1.0])
|
| 62 |
+
|
| 63 |
+
# Nonlinear cinematic curve
|
| 64 |
+
curve = drama ** 2.2
|
| 65 |
+
|
| 66 |
+
# Blend strength influenced by model intensity
|
| 67 |
+
strength = np.clip(curve * intensity, 0.0, 1.0)
|
| 68 |
+
|
| 69 |
+
# Blend toward white baseline
|
| 70 |
+
blended = white * (1 - strength) + color * strength
|
| 71 |
+
|
| 72 |
+
# Subtle energy-based brightness shaping
|
| 73 |
+
brightness_boost = 0.9 + (0.25 * energy)
|
| 74 |
+
blended = blended * brightness_boost
|
| 75 |
+
|
| 76 |
+
blended = np.clip(blended, 0.0, 1.0)
|
| 77 |
+
|
| 78 |
return {
|
| 79 |
+
"R": int(blended[0] * 255),
|
| 80 |
+
"G": int(blended[1] * 255),
|
| 81 |
+
"B": int(blended[2] * 255),
|
| 82 |
+
"E": energy,
|
| 83 |
+
"I": intensity
|
| 84 |
}
|
| 85 |
|
| 86 |
+
|
| 87 |
+
# -------------------------------------------------
|
| 88 |
+
# Render HTML Block
|
| 89 |
+
# -------------------------------------------------
|
| 90 |
+
|
| 91 |
def render_color(rgb):
|
| 92 |
return f"""
|
| 93 |
<div style="
|
|
|
|
| 96 |
border-radius:18px;
|
| 97 |
background: rgb({rgb['R']},{rgb['G']},{rgb['B']});
|
| 98 |
box-shadow: 0px 6px 32px rgba(0,0,0,0.25);
|
| 99 |
+
transition: all 0.35s cubic-bezier(.4,0,.2,1);
|
| 100 |
"></div>
|
| 101 |
"""
|
| 102 |
|