Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,75 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import spaces
|
3 |
|
4 |
-
|
5 |
-
def
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
fn=
|
14 |
-
inputs=
|
15 |
-
outputs=
|
16 |
)
|
17 |
|
18 |
demo.launch() # Kein share=True
|
|
|
1 |
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
import spaces
|
5 |
|
6 |
+
# Funktion zum Installieren von Infinigen (einmalig beim Start)
|
7 |
+
def install_infinigen():
|
8 |
+
infinigen_dir = "infinigen"
|
9 |
+
if not os.path.exists(infinigen_dir):
|
10 |
+
print("Klone Infinigen...")
|
11 |
+
subprocess.run(["git", "clone", "https://github.com/princeton-vl/infinigen.git"], check=True)
|
12 |
+
|
13 |
+
# Blender-Python-Pfad (anpassen falls nötig)
|
14 |
+
blender_python = "/usr/share/blender/4.2/python/bin/python3.10"
|
15 |
+
if not os.path.exists(blender_python):
|
16 |
+
# Fallback: Suche nach Blender-Python
|
17 |
+
blender_python = subprocess.run(
|
18 |
+
["find", "/usr", "-name", "python3.10", "-path", "*/blender/*"],
|
19 |
+
capture_output=True, text=True
|
20 |
+
).stdout.strip().split("\n")[0]
|
21 |
+
print(f"Blender Python gefunden unter: {blender_python}")
|
22 |
+
|
23 |
+
# Installiere Infinigen mit Blender-Python
|
24 |
+
subprocess.run([
|
25 |
+
blender_python, "-m", "pip", "install", "-e", f"{infinigen_dir}[terrain,vis]", "--no-deps"
|
26 |
+
], check=True)
|
27 |
+
print("Infinigen installiert.")
|
28 |
|
29 |
+
# Infinigen beim Start installieren
|
30 |
+
install_infinigen()
|
31 |
+
|
32 |
+
# Funktion zum Generieren einer Szene mit ZeroGPU
|
33 |
+
@spaces.GPU
|
34 |
+
def generate_scene(seed):
|
35 |
+
output_dir = "outputs"
|
36 |
+
os.makedirs(output_dir, exist_ok=True)
|
37 |
+
|
38 |
+
blender_python = "/usr/share/blender/4.2/python/bin/python3.10" # Muss ggf. angepasst werden
|
39 |
+
command = [
|
40 |
+
blender_python, "-m", "infinigen.datagen.manage_jobs",
|
41 |
+
"--output_folder", output_dir,
|
42 |
+
"--num_scenes", "1",
|
43 |
+
"--specific_seed", str(int(seed)),
|
44 |
+
"--configs", "infinigen/infinigen_examples/configs/desert.gin",
|
45 |
+
"infinigen/infinigen_examples/configs/simple.gin",
|
46 |
+
"--pipeline_configs", "infinigen/infinigen_examples/configs/local_16GB.gin",
|
47 |
+
"infinigen/infinigen_examples/configs/monocular.gin",
|
48 |
+
"infinigen/infinigen_examples/configs/blender_gt.gin"
|
49 |
+
]
|
50 |
+
|
51 |
+
try:
|
52 |
+
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
53 |
+
print("STDOUT:", result.stdout)
|
54 |
+
print("STDERR:", result.stderr)
|
55 |
+
output_path = os.path.join(output_dir, "0000000000.png")
|
56 |
+
if os.path.exists(output_path):
|
57 |
+
return output_path
|
58 |
+
return f"Fehler: Bild nicht gefunden. STDERR: {result.stderr}"
|
59 |
+
except subprocess.CalledProcessError as e:
|
60 |
+
return f"Fehler: {e.stderr}"
|
61 |
+
|
62 |
+
# Gradio-Oberfläche
|
63 |
+
with gr.Blocks(title="Infinigen Demo") as demo:
|
64 |
+
gr.Markdown("## Infinigen Scene Generator")
|
65 |
+
seed_input = gr.Number(label="Seed", value=0, precision=0)
|
66 |
+
output_image = gr.Image(label="Generierte Szene")
|
67 |
+
generate_button = gr.Button("Szene generieren")
|
68 |
|
69 |
+
generate_button.click(
|
70 |
+
fn=generate_scene,
|
71 |
+
inputs=[seed_input],
|
72 |
+
outputs=[output_image]
|
73 |
)
|
74 |
|
75 |
demo.launch() # Kein share=True
|