File size: 1,305 Bytes
e42a6f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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():
    setup_blender()
    # Path to your .blend file
    blend_file = "path/to/your/model.blend"
    # Output file
    output_file = "output.png"
    # Render command
    render_command = f"blender -b {blend_file} -o //{output_file} -f 1"
    subprocess.run(render_command.split())
    return output_file

def render_interface():
    with gr.Blocks() as demo:
        gr.Markdown("# Blender Rendering with Gradio")
        with gr.Row():
            blend_file_input = gr.File(label="Upload your .blend file")
        render_button = gr.Button("Render")
        output_image = gr.Image(label="Rendered Image")
        
        render_button.click(
            fn=render_model,
            inputs=[],
            outputs=[output_image]
        )
    return demo

if __name__ == "__main__":
    render_interface().launch()