Spaces:
Sleeping
Sleeping
File size: 1,671 Bytes
4373daa 6fa48ff 9108d7c 4a674ae 6fa48ff 4a674ae 9108d7c 4373daa 4a674ae 6fa48ff |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import gradio as gr
import bpy
import tempfile
def enable_GPUS():
bpy.data.scenes[0].render.engine = "CYCLES" #"CYCLES"
# Set the device_type
bpy.context.preferences.addons[
"cycles"
].preferences.compute_device_type = "CUDA" # or "OPENCL"
# Set the device and feature set
bpy.context.scene.cycles.device = "GPU"
for scene in bpy.data.scenes:
scene.cycles.device = "GPU"
bpy.context.preferences.addons["cycles"].preferences.get_devices()
print(bpy.context.preferences.addons["cycles"].preferences.compute_device_type)
for d in bpy.context.preferences.addons["cycles"].preferences.devices:
d["use"] = True # Using all devices, include GPU and CPU
print(d["name"])
def generate():
with tempfile.NamedTemporaryFile(suffix=".JPEG", delete=False) as f:
bpy.context.scene.render.resolution_y = 200
bpy.context.scene.render.resolution_x = 400
bpy.context.scene.render.image_settings.file_format = "JPEG"
bpy.context.scene.render.filepath = f.name
enable_GPUS()
bpy.ops.render.render(animation=False, write_still=True)
bpy.data.images["Render Result"].save_render(
filepath=bpy.context.scene.render.filepath
)
bpy.app.handlers.render_stats.clear()
return f.name
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
render_btn = gr.Button("Render")
with gr.Column(scale=3):
image = gr.Image(type="filepath")
render_btn.click(
generate,
outputs=[image],
)
demo.queue(concurrency_count=1)
demo.launch(debug=True, inline=True)
w |