import os import subprocess import gradio as gr def setup_blender(): if not os.path.exists('blender-3.0.0-linux-x64.tar.xz'): subprocess.run(['wget', 'https://download.blender.org/release/Blender3.0/blender-3.0.0-linux-x64.tar.xz']) if not os.path.exists('blender-3.0.0-linux-x64'): subprocess.run(['tar', '-xf', 'blender-3.0.0-linux-x64.tar.xz']) os.environ['PATH'] += os.pathsep + os.path.abspath('./blender-3.0.0-linux-x64/blender') def render_model(blend_file): setup_blender() # Save the uploaded blend file blend_file_path = os.path.join("temp", blend_file.name) with open(blend_file_path, "wb") as f: f.write(blend_file.read()) # Output file output_file = "output.png" # Render command render_command = f"blender -b {blend_file_path} -o //{output_file} -f 1" subprocess.run(render_command.split()) return output_file def render_interface(): with gr.Interface( fn=render_model, inputs=gr.inputs.File(label="Upload your .blend file"), outputs=gr.outputs.Image(label="Rendered Image") ) as iface: iface.launch() if __name__ == "__main__": render_interface()