Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import torch
|
|
| 8 |
import spaces # ู
ูู
ูู @spaces.GPU
|
| 9 |
|
| 10 |
# =============================
|
| 11 |
-
# ุฅุนุฏุงุฏ ู
ูุชุงุญ Gemini (
|
| 12 |
# =============================
|
| 13 |
|
| 14 |
GEMINI_API_KEY = "AIzaSyAvm28ZnTMaZ1Jtg9sYM-EO4qlAN2W4BIQ"
|
|
@@ -43,15 +43,17 @@ def fix_with_gemini(raw_text: str) -> str:
|
|
| 43 |
# =============================
|
| 44 |
|
| 45 |
WEIGHTS_PATH = "best.pt"
|
| 46 |
-
IMG_SIZE =
|
| 47 |
-
CONF_THRESHOLD = 0.
|
| 48 |
|
| 49 |
-
# ุฅุนุฏุงุฏุงุช ุชุฌู
ูุน ุงูุญุฑูู
|
| 50 |
MIN_STABLE_FRAMES = 1
|
| 51 |
FRAME_SKIP = 1
|
| 52 |
MAX_FRAMES = 1000
|
| 53 |
WORD_GAP_FRAMES = 10
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
arabic_map = {
|
| 56 |
"aleff": "ุง",
|
| 57 |
"bb": "ุจ",
|
|
@@ -87,15 +89,13 @@ arabic_map = {
|
|
| 87 |
"la": "ูุง",
|
| 88 |
}
|
| 89 |
|
| 90 |
-
# ููุณุชุฎุฏู
ู
ูุฏูู ุนุงูู
ู ููู ูุญู
ููู ุนูุฏ ุฃูู ุงุณุชุฎุฏุงู
ููุท
|
| 91 |
yolo_model = None
|
| 92 |
DEVICE = "cpu"
|
| 93 |
|
| 94 |
|
| 95 |
def get_model():
|
| 96 |
"""
|
| 97 |
-
ูุญู
ูู YOLO ู
ุฑุฉ ูุงุญุฏุฉุ ููุญุงูู
|
| 98 |
-
ููุณุชุฏุนู ุฏุงุฎู ุฏุงูุฉ ุนูููุง @spaces.GPU ุจุนุฏ ู
ุง ุงูู GPU ูุดุชุบู ูุนูููุง.
|
| 99 |
"""
|
| 100 |
global yolo_model, DEVICE
|
| 101 |
|
|
@@ -104,7 +104,6 @@ def get_model():
|
|
| 104 |
yolo_model = YOLO(WEIGHTS_PATH)
|
| 105 |
print("๐ Classes:", yolo_model.names)
|
| 106 |
|
| 107 |
-
# ูุนูุฏ ุงูุชุญูู ู
ู CUDA ููุง (ุจุนุฏ ู
ุง GPU ูุดุชุบู ูู Spaces)
|
| 108 |
if torch.cuda.is_available():
|
| 109 |
if DEVICE != "cuda":
|
| 110 |
DEVICE = "cuda"
|
|
@@ -114,25 +113,66 @@ def get_model():
|
|
| 114 |
except Exception as e:
|
| 115 |
print("โ ๏ธ ุชุนุฐุฑ ููู ุงูู
ูุฏูู ุฅูู cuda:", e)
|
| 116 |
else:
|
|
|
|
|
|
|
| 117 |
DEVICE = "cpu"
|
| 118 |
-
print("โ ๏ธ CUDA ุบูุฑ ู
ุชููุฑุ ุณูุชู
ุงุณุชุฎุฏุงู
CPU.")
|
| 119 |
|
| 120 |
return yolo_model
|
| 121 |
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
# =============================
|
| 124 |
# ุถุบุท ุงูููุฏูู ูุจู ุงูู
ุนุงูุฌุฉ
|
| 125 |
# =============================
|
| 126 |
|
| 127 |
-
def preprocess_video(input_path: str,
|
| 128 |
"""
|
| 129 |
-
|
| 130 |
-
|
|
|
|
| 131 |
"""
|
| 132 |
cap = cv2.VideoCapture(input_path)
|
| 133 |
if not cap.isOpened():
|
| 134 |
print("[preprocess] ุชุนุฐุฑ ูุชุญ ุงูููุฏููุ ุณูุณุชุฎุฏู
ุงูู
ูู ุงูุฃุตูู ูู
ุง ูู.")
|
| 135 |
-
return input_path
|
| 136 |
|
| 137 |
orig_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 138 |
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
@@ -145,13 +185,26 @@ def preprocess_video(input_path: str, target_width: int = 640, target_fps: int =
|
|
| 145 |
frame_step = max(1, int(round(orig_fps / target_fps)))
|
| 146 |
out_fps = orig_fps / frame_step
|
| 147 |
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
fd, tmp_path = tempfile.mkstemp(suffix=".mp4")
|
| 151 |
os.close(fd)
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 154 |
-
out = cv2.VideoWriter(tmp_path, fourcc, out_fps, (
|
| 155 |
|
| 156 |
frame_idx = 0
|
| 157 |
while True:
|
|
@@ -160,14 +213,18 @@ def preprocess_video(input_path: str, target_width: int = 640, target_fps: int =
|
|
| 160 |
break
|
| 161 |
|
| 162 |
if frame_idx % frame_step == 0:
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
frame_idx += 1
|
| 167 |
|
| 168 |
cap.release()
|
| 169 |
out.release()
|
| 170 |
-
print(f"[preprocess]
|
| 171 |
return tmp_path
|
| 172 |
|
| 173 |
|
|
@@ -176,7 +233,7 @@ def preprocess_video(input_path: str, target_width: int = 640, target_fps: int =
|
|
| 176 |
# =============================
|
| 177 |
|
| 178 |
def detect_frame(frame_bgr):
|
| 179 |
-
model = get_model()
|
| 180 |
|
| 181 |
frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
| 182 |
result = model.predict(
|
|
@@ -184,11 +241,14 @@ def detect_frame(frame_bgr):
|
|
| 184 |
conf=CONF_THRESHOLD,
|
| 185 |
imgsz=IMG_SIZE,
|
| 186 |
verbose=False,
|
| 187 |
-
device=DEVICE,
|
| 188 |
)[0]
|
| 189 |
|
| 190 |
boxes = result.boxes
|
| 191 |
|
|
|
|
|
|
|
|
|
|
| 192 |
if boxes is None or len(boxes) == 0:
|
| 193 |
return [], frame_bgr
|
| 194 |
|
|
@@ -220,13 +280,13 @@ def detect_frame(frame_bgr):
|
|
| 220 |
|
| 221 |
|
| 222 |
# =============================
|
| 223 |
-
# VIDEO โ RAW TEXT + OUTPUT VIDEO
|
| 224 |
# =============================
|
| 225 |
|
| 226 |
def extract_and_render(video_path: str):
|
| 227 |
cap = cv2.VideoCapture(video_path)
|
| 228 |
if not cap.isOpened():
|
| 229 |
-
return "", None
|
| 230 |
|
| 231 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 232 |
out_path = "processed_output.mp4"
|
|
@@ -248,6 +308,9 @@ def extract_and_render(video_path: str):
|
|
| 248 |
last_seen = None
|
| 249 |
frame_index = 0
|
| 250 |
|
|
|
|
|
|
|
|
|
|
| 251 |
while True:
|
| 252 |
ret, frame = cap.read()
|
| 253 |
if not ret:
|
|
@@ -265,6 +328,9 @@ def extract_and_render(video_path: str):
|
|
| 265 |
out.write(rendered)
|
| 266 |
|
| 267 |
if labels:
|
|
|
|
|
|
|
|
|
|
| 268 |
label = labels[0]
|
| 269 |
last_seen = frame_index
|
| 270 |
|
|
@@ -295,42 +361,61 @@ def extract_and_render(video_path: str):
|
|
| 295 |
words.append(word)
|
| 296 |
|
| 297 |
raw_text = " ".join(words).strip()
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
|
| 301 |
# =============================
|
| 302 |
# Gradio + @spaces.GPU
|
| 303 |
# =============================
|
| 304 |
|
| 305 |
-
@spaces.GPU
|
| 306 |
def run(file):
|
| 307 |
if file is None:
|
| 308 |
-
return "ูู
ูุชู
ุฑูุน ููุฏูู", "", None
|
| 309 |
|
| 310 |
video_path = file.name
|
| 311 |
|
| 312 |
-
|
|
|
|
| 313 |
|
| 314 |
-
raw, processed_path = extract_and_render(light_path)
|
| 315 |
pretty = fix_with_gemini(raw) if raw else ""
|
| 316 |
|
| 317 |
if not raw:
|
| 318 |
raw = "ูู
ูุชู
ุงูุชุนุฑู ุนูู ุฃู ูุต ู
ู ุงูุฅุดุงุฑุงุช."
|
| 319 |
|
| 320 |
-
return raw, pretty, processed_path
|
| 321 |
|
| 322 |
|
| 323 |
with gr.Blocks() as demo:
|
| 324 |
-
gr.Markdown("## ๐ค ASL โ Arabic (YOLO + Gemini) โ
|
| 325 |
|
| 326 |
inp = gr.File(label="ุงุฑูุน ููุฏูู ุงูุฅุดุงุฑุฉ")
|
| 327 |
raw = gr.Textbox(label="ุงููุต ุงูุฎุงู
", lines=3)
|
| 328 |
pretty = gr.Textbox(label="ุงููุต ุงูู
ุญุณู (Gemini)", lines=3)
|
| 329 |
video_out = gr.Video(label="ุงูููุฏูู ุจุนุฏ ุงูุจุฑูุณูุณ")
|
|
|
|
| 330 |
|
| 331 |
btn = gr.Button("ุงุจุฏุฃ ุงูู
ุนุงูุฌุฉ")
|
| 332 |
|
| 333 |
-
btn.click(run, inputs=[inp], outputs=[raw, pretty, video_out])
|
| 334 |
|
| 335 |
if __name__ == "__main__":
|
| 336 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 8 |
import spaces # ู
ูู
ูู @spaces.GPU
|
| 9 |
|
| 10 |
# =============================
|
| 11 |
+
# ุฅุนุฏุงุฏ ู
ูุชุงุญ Gemini (ุญุท ุงูู
ูุชุงุญ ููุง)
|
| 12 |
# =============================
|
| 13 |
|
| 14 |
GEMINI_API_KEY = "AIzaSyAvm28ZnTMaZ1Jtg9sYM-EO4qlAN2W4BIQ"
|
|
|
|
| 43 |
# =============================
|
| 44 |
|
| 45 |
WEIGHTS_PATH = "best.pt"
|
| 46 |
+
IMG_SIZE = 640 # ุญุฌู
ุงูุฅุฏุฎุงู ูู YOLO
|
| 47 |
+
CONF_THRESHOLD = 0.15 # ู
ุฎูุถ ุนุดุงู ููุชูุท ุฃูุซุฑ
|
| 48 |
|
|
|
|
| 49 |
MIN_STABLE_FRAMES = 1
|
| 50 |
FRAME_SKIP = 1
|
| 51 |
MAX_FRAMES = 1000
|
| 52 |
WORD_GAP_FRAMES = 10
|
| 53 |
|
| 54 |
+
# ูู ุญุงุจ ุชูุบู ุงููุต ุงูู
ุฑูุฒู (ุฒูู
)ุ ุฎููู False
|
| 55 |
+
CENTER_CROP = True
|
| 56 |
+
|
| 57 |
arabic_map = {
|
| 58 |
"aleff": "ุง",
|
| 59 |
"bb": "ุจ",
|
|
|
|
| 89 |
"la": "ูุง",
|
| 90 |
}
|
| 91 |
|
|
|
|
| 92 |
yolo_model = None
|
| 93 |
DEVICE = "cpu"
|
| 94 |
|
| 95 |
|
| 96 |
def get_model():
|
| 97 |
"""
|
| 98 |
+
ูุญู
ูู YOLO ู
ุฑุฉ ูุงุญุฏุฉุ ููุญุงูู ูุณุชุฎุฏู
CUDA ูู ู
ุชููุฑ.
|
|
|
|
| 99 |
"""
|
| 100 |
global yolo_model, DEVICE
|
| 101 |
|
|
|
|
| 104 |
yolo_model = YOLO(WEIGHTS_PATH)
|
| 105 |
print("๐ Classes:", yolo_model.names)
|
| 106 |
|
|
|
|
| 107 |
if torch.cuda.is_available():
|
| 108 |
if DEVICE != "cuda":
|
| 109 |
DEVICE = "cuda"
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
print("โ ๏ธ ุชุนุฐุฑ ููู ุงูู
ูุฏูู ุฅูู cuda:", e)
|
| 115 |
else:
|
| 116 |
+
if DEVICE != "cpu":
|
| 117 |
+
print("โ ๏ธ CUDA ุบูุฑ ู
ุชููุฑุ ุณูุชู
ุงุณุชุฎุฏุงู
CPU.")
|
| 118 |
DEVICE = "cpu"
|
|
|
|
| 119 |
|
| 120 |
return yolo_model
|
| 121 |
|
| 122 |
|
| 123 |
+
# =============================
|
| 124 |
+
# ุฏุงูุฉ ู
ุณุงุนุฏุฉ: ุชูุจูุฑ + ูุต ู
ู ุงููุณุท 640x640
|
| 125 |
+
# =============================
|
| 126 |
+
|
| 127 |
+
def resize_and_center_crop(frame, target: int = 640):
|
| 128 |
+
"""
|
| 129 |
+
- ููุจุฑ/ูุตุบุฑ ุจุญูุซ ุฃูุตุฑ ุถูุน = target
|
| 130 |
+
- ุซู
ููุต ู
ุฑุจุน 640x640 ู
ู ุงููุณุท (Zoom ูุทูู ุนูู ุงูู
ุฑูุฒ)
|
| 131 |
+
"""
|
| 132 |
+
h, w = frame.shape[:2]
|
| 133 |
+
short_side = min(w, h)
|
| 134 |
+
if short_side <= 0:
|
| 135 |
+
return frame
|
| 136 |
+
|
| 137 |
+
scale = target / short_side
|
| 138 |
+
new_w = int(w * scale)
|
| 139 |
+
new_h = int(h * scale)
|
| 140 |
+
|
| 141 |
+
frame = cv2.resize(frame, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
| 142 |
+
|
| 143 |
+
h, w = frame.shape[:2]
|
| 144 |
+
x1 = max(0, (w - target) // 2)
|
| 145 |
+
y1 = max(0, (h - target) // 2)
|
| 146 |
+
x2 = x1 + target
|
| 147 |
+
y2 = y1 + target
|
| 148 |
+
|
| 149 |
+
x2 = min(x2, w)
|
| 150 |
+
y2 = min(y2, h)
|
| 151 |
+
|
| 152 |
+
crop = frame[y1:y2, x1:x2]
|
| 153 |
+
|
| 154 |
+
# ูู ูุณุจุจ ู
ุง ุงููุต ุฃุตุบุฑ ู
ู 640x640ุ ูุฑุฌุน ูุถุจุทู
|
| 155 |
+
ch, cw = crop.shape[:2]
|
| 156 |
+
if ch != target or cw != target:
|
| 157 |
+
crop = cv2.resize(crop, (target, target), interpolation=cv2.INTER_AREA)
|
| 158 |
+
|
| 159 |
+
return crop
|
| 160 |
+
|
| 161 |
+
|
| 162 |
# =============================
|
| 163 |
# ุถุบุท ุงูููุฏูู ูุจู ุงูู
ุนุงูุฌุฉ
|
| 164 |
# =============================
|
| 165 |
|
| 166 |
+
def preprocess_video(input_path: str, target_short_side: int = 640, target_fps: int = 8) -> str:
|
| 167 |
"""
|
| 168 |
+
ูุถุจุท ุงูููุฏูู ุจุญูุซ:
|
| 169 |
+
- ุฃูุตุฑ ุถูุน โ target_short_side
|
| 170 |
+
- ู
ุน ุฎูุงุฑ ูุต ู
ุฑูุฒู 640x640 (Zoom) ูู CENTER_CROP = True
|
| 171 |
"""
|
| 172 |
cap = cv2.VideoCapture(input_path)
|
| 173 |
if not cap.isOpened():
|
| 174 |
print("[preprocess] ุชุนุฐุฑ ูุชุญ ุงูููุฏููุ ุณูุณุชุฎุฏู
ุงูู
ูู ุงูุฃุตูู ูู
ุง ูู.")
|
| 175 |
+
return input_path
|
| 176 |
|
| 177 |
orig_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 178 |
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
|
|
| 185 |
frame_step = max(1, int(round(orig_fps / target_fps)))
|
| 186 |
out_fps = orig_fps / frame_step
|
| 187 |
|
| 188 |
+
short_side = min(w, h)
|
| 189 |
+
if short_side <= 0:
|
| 190 |
+
scale = 1.0
|
| 191 |
+
else:
|
| 192 |
+
scale = target_short_side / short_side
|
| 193 |
+
|
| 194 |
+
new_w = int(w * scale)
|
| 195 |
+
new_h = int(h * scale)
|
| 196 |
|
| 197 |
fd, tmp_path = tempfile.mkstemp(suffix=".mp4")
|
| 198 |
os.close(fd)
|
| 199 |
|
| 200 |
+
# ูู ุจููุต 640x640 ูุฎูู ุงูู writer ุจุฑุถู 640x640
|
| 201 |
+
if CENTER_CROP:
|
| 202 |
+
out_w, out_h = IMG_SIZE, IMG_SIZE
|
| 203 |
+
else:
|
| 204 |
+
out_w, out_h = new_w, new_h
|
| 205 |
+
|
| 206 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 207 |
+
out = cv2.VideoWriter(tmp_path, fourcc, out_fps, (out_w, out_h))
|
| 208 |
|
| 209 |
frame_idx = 0
|
| 210 |
while True:
|
|
|
|
| 213 |
break
|
| 214 |
|
| 215 |
if frame_idx % frame_step == 0:
|
| 216 |
+
if CENTER_CROP:
|
| 217 |
+
processed = resize_and_center_crop(frame, target=IMG_SIZE)
|
| 218 |
+
else:
|
| 219 |
+
processed = cv2.resize(frame, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
| 220 |
+
|
| 221 |
+
out.write(processed)
|
| 222 |
|
| 223 |
frame_idx += 1
|
| 224 |
|
| 225 |
cap.release()
|
| 226 |
out.release()
|
| 227 |
+
print(f"[preprocess] orig=({w}x{h}), new=({out_w}x{out_h}), saved={tmp_path}")
|
| 228 |
return tmp_path
|
| 229 |
|
| 230 |
|
|
|
|
| 233 |
# =============================
|
| 234 |
|
| 235 |
def detect_frame(frame_bgr):
|
| 236 |
+
model = get_model()
|
| 237 |
|
| 238 |
frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
| 239 |
result = model.predict(
|
|
|
|
| 241 |
conf=CONF_THRESHOLD,
|
| 242 |
imgsz=IMG_SIZE,
|
| 243 |
verbose=False,
|
| 244 |
+
device=DEVICE,
|
| 245 |
)[0]
|
| 246 |
|
| 247 |
boxes = result.boxes
|
| 248 |
|
| 249 |
+
num_boxes = 0 if boxes is None else len(boxes)
|
| 250 |
+
print(f"[detect_frame] boxes={num_boxes}")
|
| 251 |
+
|
| 252 |
if boxes is None or len(boxes) == 0:
|
| 253 |
return [], frame_bgr
|
| 254 |
|
|
|
|
| 280 |
|
| 281 |
|
| 282 |
# =============================
|
| 283 |
+
# VIDEO โ RAW TEXT + OUTPUT VIDEO + DEBUG
|
| 284 |
# =============================
|
| 285 |
|
| 286 |
def extract_and_render(video_path: str):
|
| 287 |
cap = cv2.VideoCapture(video_path)
|
| 288 |
if not cap.isOpened():
|
| 289 |
+
return "", None, "ุชุนุฐุฑ ูุชุญ ุงูููุฏูู ูู extract_and_render"
|
| 290 |
|
| 291 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 292 |
out_path = "processed_output.mp4"
|
|
|
|
| 308 |
last_seen = None
|
| 309 |
frame_index = 0
|
| 310 |
|
| 311 |
+
frames_with_dets = 0
|
| 312 |
+
debug_lines = []
|
| 313 |
+
|
| 314 |
while True:
|
| 315 |
ret, frame = cap.read()
|
| 316 |
if not ret:
|
|
|
|
| 328 |
out.write(rendered)
|
| 329 |
|
| 330 |
if labels:
|
| 331 |
+
frames_with_dets += 1
|
| 332 |
+
debug_lines.append(f"frame {frame_index}: {labels}")
|
| 333 |
+
|
| 334 |
label = labels[0]
|
| 335 |
last_seen = frame_index
|
| 336 |
|
|
|
|
| 361 |
words.append(word)
|
| 362 |
|
| 363 |
raw_text = " ".join(words).strip()
|
| 364 |
+
|
| 365 |
+
if not debug_lines:
|
| 366 |
+
debug_info = (
|
| 367 |
+
f"total_frames={frame_index}, frames_with_detections=0\n"
|
| 368 |
+
"ูู
ูุชู
ุฑุตุฏ ุฃู ุตูุงุฏูู (boxes) ู
ู YOLO ูู ุฃู ูุฑูู
.\n"
|
| 369 |
+
"ุชุญูู ู
ู:\n"
|
| 370 |
+
"- ุฃู best.pt ูู ู
ูุฏูู detection ูุชุฏุฑูุจู ุณููู
.\n"
|
| 371 |
+
"- ุฃู ุงูููุฏูู ู
ุดุงุจู ูุชุฏุฑูุจ ุงูู
ูุฏูู ู
ู ูุงุญูุฉ ูุถุนูุฉ ุงููุฏ ูุงููุงู
ูุฑุง."
|
| 372 |
+
)
|
| 373 |
+
else:
|
| 374 |
+
sample = "\n".join(debug_lines[:30])
|
| 375 |
+
debug_info = (
|
| 376 |
+
f"total_frames={frame_index}, frames_with_detections={frames_with_dets}\n"
|
| 377 |
+
"ุฃู
ุซูุฉ ู
ู ุงููุฑูู
ุงุช ุงููู ูููุง ุญุฑูู:\n"
|
| 378 |
+
f"{sample}"
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
return raw_text, out_path, debug_info
|
| 382 |
|
| 383 |
|
| 384 |
# =============================
|
| 385 |
# Gradio + @spaces.GPU
|
| 386 |
# =============================
|
| 387 |
|
| 388 |
+
@spaces.GPU
|
| 389 |
def run(file):
|
| 390 |
if file is None:
|
| 391 |
+
return "ูู
ูุชู
ุฑูุน ููุฏูู", "", None, "ูู
ูุชู
ุฑูุน ููุฏูู"
|
| 392 |
|
| 393 |
video_path = file.name
|
| 394 |
|
| 395 |
+
# ุงูุชูุจูุฑ + center crop 640x640
|
| 396 |
+
light_path = preprocess_video(video_path, target_short_side=640, target_fps=8)
|
| 397 |
|
| 398 |
+
raw, processed_path, debug_info = extract_and_render(light_path)
|
| 399 |
pretty = fix_with_gemini(raw) if raw else ""
|
| 400 |
|
| 401 |
if not raw:
|
| 402 |
raw = "ูู
ูุชู
ุงูุชุนุฑู ุนูู ุฃู ูุต ู
ู ุงูุฅุดุงุฑุงุช."
|
| 403 |
|
| 404 |
+
return raw, pretty, processed_path, debug_info
|
| 405 |
|
| 406 |
|
| 407 |
with gr.Blocks() as demo:
|
| 408 |
+
gr.Markdown("## ๐ค ASL โ Arabic (YOLO + Gemini) โ ู
ุน ุชูุจูุฑ ุฃูุถู ููููุฏูููุงุช ุงูุนุฑุถูุฉ")
|
| 409 |
|
| 410 |
inp = gr.File(label="ุงุฑูุน ููุฏูู ุงูุฅุดุงุฑุฉ")
|
| 411 |
raw = gr.Textbox(label="ุงููุต ุงูุฎุงู
", lines=3)
|
| 412 |
pretty = gr.Textbox(label="ุงููุต ุงูู
ุญุณู (Gemini)", lines=3)
|
| 413 |
video_out = gr.Video(label="ุงูููุฏูู ุจุนุฏ ุงูุจุฑูุณูุณ")
|
| 414 |
+
debug_box = gr.Textbox(label="Debug info", lines=10)
|
| 415 |
|
| 416 |
btn = gr.Button("ุงุจุฏุฃ ุงูู
ุนุงูุฌุฉ")
|
| 417 |
|
| 418 |
+
btn.click(run, inputs=[inp], outputs=[raw, pretty, video_out, debug_box])
|
| 419 |
|
| 420 |
if __name__ == "__main__":
|
| 421 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|