Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,45 +2,48 @@ import gradio as gr
|
|
2 |
import subprocess
|
3 |
import os
|
4 |
import spaces
|
|
|
5 |
|
|
|
6 |
def find_blender_python():
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
"
|
11 |
-
|
12 |
-
|
13 |
-
]
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
# Debugging: Blender selbst suchen
|
26 |
-
blender_bin = subprocess.run(["find", "/", "-name", "blender", "-type", "f"], capture_output=True, text=True)
|
27 |
-
print(f"Blender-Binär gefunden: {blender_bin.stdout}")
|
28 |
raise RuntimeError("Blender Python-Interpreter nicht gefunden!")
|
29 |
|
30 |
# Funktion zum Installieren von Infinigen
|
31 |
def install_infinigen():
|
32 |
-
infinigen_dir = "infinigen"
|
33 |
-
if not
|
34 |
print("Klone Infinigen...")
|
35 |
subprocess.run(["git", "clone", "https://github.com/princeton-vl/infinigen.git"], check=True)
|
36 |
|
37 |
blender_python = find_blender_python()
|
38 |
-
if not blender_python:
|
39 |
-
raise RuntimeError("Blender Python-Interpreter nicht gefunden!")
|
40 |
-
|
41 |
-
print(f"Blender Python gefunden unter: {blender_python}")
|
42 |
subprocess.run([
|
43 |
-
blender_python, "-m", "pip", "install", "-e",
|
44 |
], check=True)
|
45 |
print("Infinigen installiert.")
|
46 |
|
@@ -48,40 +51,37 @@ def install_infinigen():
|
|
48 |
try:
|
49 |
install_infinigen()
|
50 |
except Exception as e:
|
51 |
-
print(f"Fehler bei
|
52 |
|
53 |
# Funktion zum Generieren einer Szene mit ZeroGPU
|
54 |
@spaces.GPU
|
55 |
def generate_scene(seed):
|
56 |
-
output_dir = "outputs"
|
57 |
-
|
58 |
-
|
59 |
-
blender_python = find_blender_python()
|
60 |
-
if not blender_python:
|
61 |
-
return "Fehler: Blender Python-Interpreter nicht gefunden!"
|
62 |
-
|
63 |
-
command = [
|
64 |
-
blender_python, "-m", "infinigen.datagen.manage_jobs",
|
65 |
-
"--output_folder", output_dir,
|
66 |
-
"--num_scenes", "1",
|
67 |
-
"--specific_seed", str(int(seed)),
|
68 |
-
"--configs", "infinigen/infinigen_examples/configs/desert.gin",
|
69 |
-
"infinigen/infinigen_examples/configs/simple.gin",
|
70 |
-
"--pipeline_configs", "infinigen/infinigen_examples/configs/local_16GB.gin",
|
71 |
-
"infinigen/infinigen_examples/configs/monocular.gin",
|
72 |
-
"infinigen/infinigen_examples/configs/blender_gt.gin"
|
73 |
-
]
|
74 |
|
75 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
77 |
-
print("STDOUT:
|
78 |
-
print("STDERR:
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
return f"Fehler: Bild nicht gefunden. STDERR: {result.stderr}"
|
83 |
except subprocess.CalledProcessError as e:
|
84 |
return f"Fehler: {e.stderr}"
|
|
|
|
|
85 |
|
86 |
# Gradio-Oberfläche
|
87 |
with gr.Blocks(title="Infinigen Demo") as demo:
|
@@ -90,10 +90,6 @@ with gr.Blocks(title="Infinigen Demo") as demo:
|
|
90 |
output_image = gr.Image(label="Generierte Szene")
|
91 |
generate_button = gr.Button("Szene generieren")
|
92 |
|
93 |
-
generate_button.click(
|
94 |
-
fn=generate_scene,
|
95 |
-
inputs=[seed_input],
|
96 |
-
outputs=[output_image]
|
97 |
-
)
|
98 |
|
99 |
demo.launch()
|
|
|
2 |
import subprocess
|
3 |
import os
|
4 |
import spaces
|
5 |
+
from pathlib import Path
|
6 |
|
7 |
+
# Funktion zum automatischen Finden des Blender-Python-Interpreters
|
8 |
def find_blender_python():
|
9 |
+
# Suche nach Blender-Binär
|
10 |
+
blender_bin = next(iter(Path("/").glob("**/blender")), None)
|
11 |
+
if not blender_bin:
|
12 |
+
raise RuntimeError("Blender-Binär nicht gefunden!")
|
13 |
+
|
14 |
+
print(f"Blender-Binär gefunden: {blender_bin}")
|
|
|
15 |
|
16 |
+
# Erkenne Blender-Version
|
17 |
+
version_result = subprocess.run([str(blender_bin), "-v"], capture_output=True, text=True)
|
18 |
+
blender_version = next((line.split()[1] for line in version_result.stdout.split("\n") if "Blender" in line and "." in line), None)
|
19 |
+
print(f"Blender-Version erkannt: {blender_version or 'unbekannt'}")
|
20 |
|
21 |
+
# Suche nach Python-Interpreter
|
22 |
+
base_path = Path("/usr/share/blender") if blender_version else Path("/")
|
23 |
+
python_patterns = [
|
24 |
+
f"{base_path}/{blender_version}/python/bin/python*",
|
25 |
+
f"{base_path}/*/python/bin/python*",
|
26 |
+
"/usr/lib/blender/*/python/bin/python*"
|
27 |
+
]
|
28 |
+
|
29 |
+
for pattern in python_patterns:
|
30 |
+
python_bin = next(iter(Path().glob(pattern)), None)
|
31 |
+
if python_bin and python_bin.is_file():
|
32 |
+
print(f"Blender Python gefunden: {python_bin}")
|
33 |
+
return str(python_bin)
|
34 |
|
|
|
|
|
|
|
35 |
raise RuntimeError("Blender Python-Interpreter nicht gefunden!")
|
36 |
|
37 |
# Funktion zum Installieren von Infinigen
|
38 |
def install_infinigen():
|
39 |
+
infinigen_dir = Path("infinigen")
|
40 |
+
if not infinigen_dir.exists():
|
41 |
print("Klone Infinigen...")
|
42 |
subprocess.run(["git", "clone", "https://github.com/princeton-vl/infinigen.git"], check=True)
|
43 |
|
44 |
blender_python = find_blender_python()
|
|
|
|
|
|
|
|
|
45 |
subprocess.run([
|
46 |
+
blender_python, "-m", "pip", "install", "-e", str(infinigen_dir) + "[terrain,vis]", "--no-deps", "--user"
|
47 |
], check=True)
|
48 |
print("Infinigen installiert.")
|
49 |
|
|
|
51 |
try:
|
52 |
install_infinigen()
|
53 |
except Exception as e:
|
54 |
+
print(f"Fehler bei Infinigen-Installation: {e}")
|
55 |
|
56 |
# Funktion zum Generieren einer Szene mit ZeroGPU
|
57 |
@spaces.GPU
|
58 |
def generate_scene(seed):
|
59 |
+
output_dir = Path("outputs")
|
60 |
+
output_dir.mkdir(exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
try:
|
63 |
+
blender_python = find_blender_python()
|
64 |
+
command = [
|
65 |
+
blender_python, "-m", "infinigen.datagen.manage_jobs",
|
66 |
+
"--output_folder", str(output_dir),
|
67 |
+
"--num_scenes", "1",
|
68 |
+
"--specific_seed", str(int(seed)),
|
69 |
+
"--configs", "infinigen/infinigen_examples/configs/desert.gin",
|
70 |
+
"infinigen/infinigen_examples/configs/simple.gin",
|
71 |
+
"--pipeline_configs", "infinigen/infinigen_examples/configs/local_16GB.gin",
|
72 |
+
"infinigen/infinigen_examples/configs/monocular.gin",
|
73 |
+
"infinigen/infinigen_examples/configs/blender_gt.gin"
|
74 |
+
]
|
75 |
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
76 |
+
print(f"STDOUT: {result.stdout}")
|
77 |
+
print(f"STDERR: {result.stderr}")
|
78 |
+
|
79 |
+
output_path = output_dir / "0000000000.png"
|
80 |
+
return str(output_path) if output_path.exists() else f"Fehler: Bild nicht gefunden. STDERR: {result.stderr}"
|
|
|
81 |
except subprocess.CalledProcessError as e:
|
82 |
return f"Fehler: {e.stderr}"
|
83 |
+
except Exception as e:
|
84 |
+
return f"Fehler beim Generieren: {e}"
|
85 |
|
86 |
# Gradio-Oberfläche
|
87 |
with gr.Blocks(title="Infinigen Demo") as demo:
|
|
|
90 |
output_image = gr.Image(label="Generierte Szene")
|
91 |
generate_button = gr.Button("Szene generieren")
|
92 |
|
93 |
+
generate_button.click(fn=generate_scene, inputs=[seed_input], outputs=[output_image])
|
|
|
|
|
|
|
|
|
94 |
|
95 |
demo.launch()
|