Spaces:
Sleeping
Sleeping
import gradio as gr | |
import subprocess | |
import os | |
import spaces | |
def find_blender_python(): | |
possible_paths = [ | |
"/usr/share/blender/4.2/python/bin/python3.10", | |
"/usr/share/blender/3.6/python/bin/python3.10", | |
"/usr/share/blender/3.5/python/bin/python3.10", | |
"/usr/share/blender/3.1/python/bin/python3.10", | |
"/usr/lib/blender/3.1/python/bin/python3.10" | |
] | |
for path in possible_paths: | |
if os.path.exists(path): | |
return path | |
# Breiterer Fallback-Suchbefehl | |
result = subprocess.run(["find", "/", "-name", "python3.*", "-path", "*/blender/*", "-type", "f"], capture_output=True, text=True) | |
paths = result.stdout.strip().split("\n") | |
if paths and paths[0] and os.path.exists(paths[0]): | |
return paths[0] | |
# Debugging: Blender selbst suchen | |
blender_bin = subprocess.run(["find", "/", "-name", "blender", "-type", "f"], capture_output=True, text=True) | |
print(f"Blender-Binär gefunden: {blender_bin.stdout}") | |
raise RuntimeError("Blender Python-Interpreter nicht gefunden!") | |
# Funktion zum Installieren von Infinigen | |
def install_infinigen(): | |
infinigen_dir = "infinigen" | |
if not os.path.exists(infinigen_dir): | |
print("Klone Infinigen...") | |
subprocess.run(["git", "clone", "https://github.com/princeton-vl/infinigen.git"], check=True) | |
blender_python = find_blender_python() | |
if not blender_python: | |
raise RuntimeError("Blender Python-Interpreter nicht gefunden!") | |
print(f"Blender Python gefunden unter: {blender_python}") | |
subprocess.run([ | |
blender_python, "-m", "pip", "install", "-e", f"{infinigen_dir}[terrain,vis]", "--no-deps" | |
], check=True) | |
print("Infinigen installiert.") | |
# Infinigen beim Start installieren | |
try: | |
install_infinigen() | |
except Exception as e: | |
print(f"Fehler bei der Installation von Infinigen: {e}") | |
# Funktion zum Generieren einer Szene mit ZeroGPU | |
def generate_scene(seed): | |
output_dir = "outputs" | |
os.makedirs(output_dir, exist_ok=True) | |
blender_python = find_blender_python() | |
if not blender_python: | |
return "Fehler: Blender Python-Interpreter nicht gefunden!" | |
command = [ | |
blender_python, "-m", "infinigen.datagen.manage_jobs", | |
"--output_folder", output_dir, | |
"--num_scenes", "1", | |
"--specific_seed", str(int(seed)), | |
"--configs", "infinigen/infinigen_examples/configs/desert.gin", | |
"infinigen/infinigen_examples/configs/simple.gin", | |
"--pipeline_configs", "infinigen/infinigen_examples/configs/local_16GB.gin", | |
"infinigen/infinigen_examples/configs/monocular.gin", | |
"infinigen/infinigen_examples/configs/blender_gt.gin" | |
] | |
try: | |
result = subprocess.run(command, capture_output=True, text=True, check=True) | |
print("STDOUT:", result.stdout) | |
print("STDERR:", result.stderr) | |
output_path = os.path.join(output_dir, "0000000000.png") | |
if os.path.exists(output_path): | |
return output_path | |
return f"Fehler: Bild nicht gefunden. STDERR: {result.stderr}" | |
except subprocess.CalledProcessError as e: | |
return f"Fehler: {e.stderr}" | |
# Gradio-Oberfläche | |
with gr.Blocks(title="Infinigen Demo") as demo: | |
gr.Markdown("## Infinigen Scene Generator") | |
seed_input = gr.Number(label="Seed", value=0, precision=0) | |
output_image = gr.Image(label="Generierte Szene") | |
generate_button = gr.Button("Szene generieren") | |
generate_button.click( | |
fn=generate_scene, | |
inputs=[seed_input], | |
outputs=[output_image] | |
) | |
demo.launch() |