NihalGazi commited on
Commit
e42a6f2
1 Parent(s): 46c9e78

Create space_handler.py

Browse files
Files changed (1) hide show
  1. space_handler.py +39 -0
space_handler.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import gradio as gr
4
+
5
+ def setup_blender():
6
+ if not os.path.exists('blender-3.0.0-linux-x64.tar.xz'):
7
+ subprocess.run(['wget', 'https://download.blender.org/release/Blender3.0/blender-3.0.0-linux-x64.tar.xz'])
8
+ if not os.path.exists('blender-3.0.0-linux-x64'):
9
+ subprocess.run(['tar', '-xf', 'blender-3.0.0-linux-x64.tar.xz'])
10
+ os.environ['PATH'] += os.pathsep + os.path.abspath('./blender-3.0.0-linux-x64/blender')
11
+
12
+ def render_model():
13
+ setup_blender()
14
+ # Path to your .blend file
15
+ blend_file = "path/to/your/model.blend"
16
+ # Output file
17
+ output_file = "output.png"
18
+ # Render command
19
+ render_command = f"blender -b {blend_file} -o //{output_file} -f 1"
20
+ subprocess.run(render_command.split())
21
+ return output_file
22
+
23
+ def render_interface():
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("# Blender Rendering with Gradio")
26
+ with gr.Row():
27
+ blend_file_input = gr.File(label="Upload your .blend file")
28
+ render_button = gr.Button("Render")
29
+ output_image = gr.Image(label="Rendered Image")
30
+
31
+ render_button.click(
32
+ fn=render_model,
33
+ inputs=[],
34
+ outputs=[output_image]
35
+ )
36
+ return demo
37
+
38
+ if __name__ == "__main__":
39
+ render_interface().launch()