Upload 6 files
Browse filesFiles changed (4)
14 unmodified lines15161718192014 unmodified lines- Blender is installed through `packages.txt`.- Output resolution is at least 2000 × 2000.- Cycles supports CPU rendering; GPU rendering is available only when the Space's Blender build and hardware expose a supported backend (CUDA/OptiX/HIP/oneAPI/Metal).- Eevee is a real-time rasterizer and may require a working GPU/graphics context on the Space host.- OBJ material textures should be uploaded together with the OBJ and MTL, and filenames should match the references inside the MTL.14 unmodified lines1516171819202114 unmodified lines- Blender is installed through `packages.txt`.- Output resolution is at least 2000 × 2000.- The CPU render button runs without requesting ZeroGPU. The GPU render button is decorated with `@spaces.GPU(duration=120)` and requests ZeroGPU quota.- Cycles supports CPU rendering; GPU rendering is available only when the Space's Blender build and hardware expose a supported backend (CUDA/OptiX/HIP/oneAPI/Metal).- Eevee is a real-time rasterizer and may require a working GPU/graphics context on the Space host.- OBJ material textures should be uploaded together with the OBJ and MTL, and filenames should match the references inside the MTL.
12345665 unmodified lines7273747576777810 unmodified lines8990919293949596979899100101102103104105106107108109110111112import os, shutil, subprocess, tempfile, uuidfrom pathlib import Pathimport gradio as grOUT = Path(tempfile.gettempdir()) / "figure_render_outputs"OUT.mkdir(exist_ok=True)65 unmodified linesscene.view_settings.view_transform="AgX"; scene.render.filepath=a.out; bpy.ops.render.render(write_still=True)'''def render_model(files, mode, engine, device, resolution, samples, azimuth, elevation, transparent):if not files: raise gr.Error("Загрузите OBJ и при необходимости MTL/текстуры.")paths=[Path(f.name if hasattr(f,"name") else str(f)) for f in files]source=next((p for p in paths if p.suffix.lower()==".obj"),None)10 unmodified linesif proc.returncode or not output.exists(): raise gr.Error("Blender не смог выполнить рендер:\n"+(proc.stderr+"\n"+proc.stdout)[-3000:])return str(output),str(output),f"Готово · {resolution}×{resolution} · {engine} · {device}"with gr.Blocks(title="3D Figure Render Studio",theme=gr.themes.Soft()) as demo:gr.Markdown("# 3D Figure Render Studio\nЗагрузи OBJ, настрой студийный свет и сохрани PNG. Для OBJ с материалами загрузи также MTL и текстуры одним набором файлов.")with gr.Row():with gr.Column(scale=1):files=gr.File(label="OBJ + MTL + текстуры",file_count="multiple",file_types=[".obj",".mtl",".png",".jpg",".jpeg",".tif",".tiff",".bmp"])mode=gr.Radio(["Beauty Render — студийный свет","Wireframe — чёрная модель + жёлтая сетка"],value="Beauty Render — студийный свет",label="Режим")engine=gr.Radio(["Eevee","Cycles"],value="Cycles",label="Рендерер")device=gr.Radio(["CPU","GPU"],value="CPU",label="Устройство (для Cycles)")resolution=gr.Dropdown(["2000","2500","3000","4000"],value="2000",label="Разрешение (квадратное, px)")samples=gr.Slider(16,256,value=64,step=16,label="Samples / качество")azimuth=gr.Slider(-180,180,value=-55,step=5,label="Азимут камеры")elevation=gr.Slider(-10,80,value=20,step=5,label="Высота камеры")transparent=gr.Checkbox(value=False,label="Прозрачный фон (без студийного пола)")run=gr.Button("Рендерить",variant="primary")with gr.Column(scale=1):preview=gr.Image(label="Результат",type="filepath")download=gr.File(label="Скачать PNG")status=gr.Markdown()run.click(render_model,[files,mode,engine,device,resolution,samples,azimuth,elevation,transparent],[preview,download,status])demo.queue(default_concurrency_limit=1).launch()123456765 unmodified lines7374757677787910 unmodified lines90919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import os, shutil, subprocess, tempfile, uuidfrom pathlib import Pathimport gradio as grimport spacesOUT = Path(tempfile.gettempdir()) / "figure_render_outputs"OUT.mkdir(exist_ok=True)65 unmodified linesscene.view_settings.view_transform="AgX"; scene.render.filepath=a.out; bpy.ops.render.render(write_still=True)'''def _render_model(files, mode, engine, device, resolution, samples, azimuth, elevation, transparent):if not files: raise gr.Error("Загрузите OBJ и при необходимости MTL/текстуры.")paths=[Path(f.name if hasattr(f,"name") else str(f)) for f in files]source=next((p for p in paths if p.suffix.lower()==".obj"),None)10 unmodified linesif proc.returncode or not output.exists(): raise gr.Error("Blender не смог выполнить рендер:\n"+(proc.stderr+"\n"+proc.stdout)[-3000:])return str(output),str(output),f"Готово · {resolution}×{resolution} · {engine} · {device}"def render_cpu(files, mode, engine, resolution, samples, azimuth, elevation, transparent):return _render_model(files, mode, engine, "CPU", resolution, samples, azimuth, elevation, transparent)@spaces.GPU(duration=120)def render_gpu(files, mode, engine, resolution, samples, azimuth, elevation, transparent):if engine != "Cycles":raise gr.Error("Выбор GPU доступен только для Cycles. Для Eevee выберите CPU или переключите рендерер на Cycles.")return _render_model(files, mode, engine, "GPU", resolution, samples, azimuth, elevation, transparent)with gr.Blocks(title="3D Figure Render Studio",theme=gr.themes.Soft()) as demo:gr.Markdown("# 3D Figure Render Studio\nЗагрузи OBJ, настрой студийный свет и сохрани PNG. Для OBJ с материалами загрузи также MTL и текстуры одним набором файлов. GPU-рендер использует ZeroGPU-квоту.")with gr.Row():with gr.Column(scale=1):files=gr.File(label="OBJ + MTL + текстуры",file_count="multiple",file_types=[".obj",".mtl",".png",".jpg",".jpeg",".tif",".tiff",".bmp"])mode=gr.Radio(["Beauty Render — студийный свет","Wireframe — чёрная модель + жёлтая сетка"],value="Beauty Render — студийный свет",label="Режим")engine=gr.Radio(["Eevee","Cycles"],value="Cycles",label="Рендерер")device=gr.Radio(["CPU","GPU"],value="CPU",label="Устройство (GPU только для Cycles)")resolution=gr.Dropdown(["2000","2500","3000","4000"],value="2000",label="Разрешение (квадратное, px)")samples=gr.Slider(16,256,value=64,step=16,label="Samples / качество")azimuth=gr.Slider(-180,180,value=-55,step=5,label="Азимут камеры")elevation=gr.Slider(-10,80,value=20,step=5,label="Высота камеры")transparent=gr.Checkbox(value=False,label="Прозрачный фон (без студийного пола)")run_cpu=gr.Button("Рендерить на CPU",variant="primary",visible=True)run_gpu=gr.Button("Рендерить на GPU (ZeroGPU)",variant="primary",visible=False)with gr.Column(scale=1):preview=gr.Image(label="Результат",type="filepath")download=gr.File(label="Скачать PNG")status=gr.Markdown()device.change(lambda d: (gr.update(visible=d=="CPU"), gr.update(visible=d=="GPU")), inputs=device, outputs=[run_cpu,run_gpu])inputs=[files,mode,engine,resolution,samples,azimuth,elevation,transparent]outputs=[preview,download,status]run_cpu.click(render_cpu,inputs=inputs,outputs=outputs)run_gpu.click(render_gpu,inputs=inputs,outputs=outputs)demo.queue(default_concurrency_limit=1).launch()
1gradio>=5.0,<6.012gradio>=5.0,<6.0spaces
README.md+1
__pycache__/app.cpython-313.pyc
app.py+20-5
requirements.txt+1