dev-bjoern commited on
Commit
cc0d1d2
·
1 Parent(s): 0467e53

Cycles CPU Rendering - funktioniert headless ohne EGL

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -26,6 +26,28 @@ def load_smollm3():
26
  return SMOLLM3_PIPE
27
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def export_glb() -> str:
30
  output_dir = tempfile.mkdtemp()
31
  glb_path = f"{output_dir}/scene_{uuid.uuid4().hex[:8]}.glb"
@@ -67,8 +89,8 @@ Only Python code, no explanations."""
67
  success = execute_bpy_code(result)
68
 
69
  if success:
70
- glb_path = export_glb()
71
- return f"Done!\n```python\n{result}\n```", glb_path
72
  else:
73
  return f"Error:\n```python\n{result}\n```", None
74
 
@@ -79,8 +101,8 @@ Only Python code, no explanations."""
79
  with gr.Blocks(title="BPY Chat") as demo:
80
  gr.Markdown("## Blender Chat")
81
 
82
- chatbot = gr.Chatbot(height=400)
83
- model_output = gr.Model3D(label="3D Scene")
84
 
85
  with gr.Row():
86
  msg = gr.Textbox(placeholder="Describe a 3D scene...", show_label=False, scale=9)
@@ -89,12 +111,12 @@ with gr.Blocks(title="BPY Chat") as demo:
89
  def respond(message, chat_history):
90
  if not message.strip():
91
  return "", chat_history, None
92
- response, glb_path = chat_with_blender(message, chat_history)
93
  chat_history.append((message, response))
94
- return "", chat_history, glb_path
95
 
96
- btn.click(respond, [msg, chatbot], [msg, chatbot, model_output])
97
- msg.submit(respond, [msg, chatbot], [msg, chatbot, model_output])
98
 
99
 
100
  if __name__ == "__main__":
 
26
  return SMOLLM3_PIPE
27
 
28
 
29
+ def render_scene() -> str:
30
+ """Render with Cycles CPU (works headless)"""
31
+ output_dir = tempfile.mkdtemp()
32
+ render_path = f"{output_dir}/render_{uuid.uuid4().hex[:8]}.png"
33
+
34
+ # Cycles CPU for headless
35
+ bpy.context.scene.render.engine = 'CYCLES'
36
+ bpy.context.scene.cycles.device = 'CPU'
37
+ bpy.context.scene.cycles.samples = 32
38
+
39
+ # Render settings
40
+ bpy.context.scene.render.filepath = render_path
41
+ bpy.context.scene.render.image_settings.file_format = 'PNG'
42
+ bpy.context.scene.render.resolution_x = 800
43
+ bpy.context.scene.render.resolution_y = 600
44
+ bpy.context.scene.render.resolution_percentage = 100
45
+
46
+ # Render
47
+ bpy.ops.render.render(write_still=True)
48
+ return render_path
49
+
50
+
51
  def export_glb() -> str:
52
  output_dir = tempfile.mkdtemp()
53
  glb_path = f"{output_dir}/scene_{uuid.uuid4().hex[:8]}.glb"
 
89
  success = execute_bpy_code(result)
90
 
91
  if success:
92
+ render_path = render_scene()
93
+ return f"Done!\n```python\n{result}\n```", render_path
94
  else:
95
  return f"Error:\n```python\n{result}\n```", None
96
 
 
101
  with gr.Blocks(title="BPY Chat") as demo:
102
  gr.Markdown("## Blender Chat")
103
 
104
+ chatbot = gr.Chatbot(height=300)
105
+ render_output = gr.Image(label="Render Preview")
106
 
107
  with gr.Row():
108
  msg = gr.Textbox(placeholder="Describe a 3D scene...", show_label=False, scale=9)
 
111
  def respond(message, chat_history):
112
  if not message.strip():
113
  return "", chat_history, None
114
+ response, render_path = chat_with_blender(message, chat_history)
115
  chat_history.append((message, response))
116
+ return "", chat_history, render_path
117
 
118
+ btn.click(respond, [msg, chatbot], [msg, chatbot, render_output])
119
+ msg.submit(respond, [msg, chatbot], [msg, chatbot, render_output])
120
 
121
 
122
  if __name__ == "__main__":