Merlimhhs commited on
Commit
a7f4d04
·
verified ·
1 Parent(s): f694560

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -49
app.py CHANGED
@@ -1,54 +1,47 @@
 
 
 
 
 
1
  import gradio as gr
2
- import torch
3
- import numpy as np
4
- from PIL import Image, ImageFilter
5
  from transformers import pipeline
6
- import zipfile
7
- import os
8
 
9
- # Carregando o modelo de alta precisão
10
- pipe = pipeline(task="depth-estimation", model="depth-anything/Depth-Anything-V2-Small-hf")
11
-
12
- def generate_binary_armor_depth(files):
13
- if not files: return None
14
-
15
- output_dir = "parallax_depths"
16
- os.makedirs(output_dir, exist_ok=True)
17
- zip_name = "Leva_Parallax_Binary_V5.zip"
18
-
19
- with zipfile.ZipFile(zip_name, 'w') as zipf:
20
- for file in files:
21
- img = Image.open(file.name).convert("RGB")
22
-
23
- # 1. Gera a Profundidade Base
24
- depth_raw = pipe(img)["depth"]
25
-
26
- # --- UPDATE V5.1: BINARY ARMOR (CORRIGIDO) ---
27
- # O tamanho do MaxFilter DEVE ser ímpar (3, 5, 7, 9, 11, 13...)
28
- # Ajustado para 11 para garantir blindagem total sem erro de sistema.
29
- depth_dilated = depth_raw.filter(ImageFilter.MaxFilter(11))
30
-
31
- # 3. SEM BLUR:
32
- # Mantemos as bordas secas para o Parallax V15 (HTML) não derreter a linha.
33
- depth_final = depth_dilated
34
- # ---------------------------------------------
35
-
36
- # Salva no ZIP
37
- base_name = os.path.basename(file.name)
38
- mask_name = f"depth_{base_name}"
39
- mask_path = os.path.join(output_dir, mask_name)
40
-
41
- depth_final.save(mask_path)
42
- zipf.write(mask_path, mask_name)
43
-
44
- return zip_name
45
-
46
- demo = gr.Interface(
47
- fn=generate_binary_armor_depth,
48
- inputs=gr.File(file_count="multiple", label="1. Envie suas artes 2.0"),
49
- outputs=gr.File(label="2. Baixe o ZIP (Máscaras Blindadas V5.1)"),
50
- title="🎥 Eternity Engine v5.1 - Binary Armor Generator",
51
- description="CORREÇÃO: Filtro ajustado para tamanho ímpar (11). Gera máscaras blindadas para o Parallax V15."
52
  )
53
 
54
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import zipfile
3
+ import tempfile
4
+ from pathlib import Path
5
+
6
  import gradio as gr
7
+ from PIL import Image
 
 
8
  from transformers import pipeline
 
 
9
 
10
+ # Depth Anything V2 é uma boa escolha para depth monocular.
11
+ # A API do Transformers mostra o uso com pipeline("depth-estimation") e pipe(image)["depth"].
12
+ pipe = pipeline(
13
+ task="depth-estimation",
14
+ model="depth-anything/Depth-Anything-V2-Small-hf"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  )
16
 
17
+ def generate_cinematic_depth(files):
18
+ if not files:
19
+ return None
20
+
21
+ out_dir = Path(tempfile.mkdtemp(prefix="parallax_depth_"))
22
+ zip_path = out_dir / "Leva_Parallax_Pro.zip"
23
+
24
+ with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zipf:
25
+ for file_obj in files:
26
+ img = Image.open(file_obj.name).convert("RGB")
27
+ depth_img = pipe(img)["depth"]
28
+
29
+ base_name = Path(file_obj.name).stem
30
+ depth_name = f"depth_{base_name}.png"
31
+ depth_path = out_dir / depth_name
32
+
33
+ depth_img.save(depth_path)
34
+ zipf.write(depth_path, arcname=depth_name)
35
+
36
+ return str(zip_path)
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("# 🎥 Eternity Engine v3.0 — Cinematic Depth")
40
+ gr.Markdown("Envie uma leva de imagens e baixe um ZIP com os mapas de profundidade.")
41
+ files = gr.File(file_count="multiple", label="1. Envie a leva de imagens")
42
+ out = gr.File(label="2. Baixe as máscaras de profundidade (ZIP)")
43
+ btn = gr.Button("Gerar Depth Maps")
44
+
45
+ btn.click(generate_cinematic_depth, inputs=files, outputs=out)
46
+
47
+ demo.launch()