Spaces:
Sleeping
Sleeping
kolibril13
commited on
Commit
·
6fa48ff
1
Parent(s):
f54caa5
add GPU again
Browse files
app.py
CHANGED
|
@@ -2,6 +2,27 @@ import gradio as gr
|
|
| 2 |
import bpy
|
| 3 |
import tempfile
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def generate():
|
| 7 |
with tempfile.NamedTemporaryFile(suffix=".JPEG", delete=False) as f:
|
|
@@ -9,6 +30,7 @@ def generate():
|
|
| 9 |
bpy.context.scene.render.resolution_x = 400
|
| 10 |
bpy.context.scene.render.image_settings.file_format = "JPEG"
|
| 11 |
bpy.context.scene.render.filepath = f.name
|
|
|
|
| 12 |
bpy.ops.render.render(animation=False, write_still=True)
|
| 13 |
bpy.data.images["Render Result"].save_render(
|
| 14 |
filepath=bpy.context.scene.render.filepath
|
|
@@ -16,7 +38,6 @@ def generate():
|
|
| 16 |
bpy.app.handlers.render_stats.clear()
|
| 17 |
return f.name
|
| 18 |
|
| 19 |
-
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
with gr.Row():
|
| 22 |
with gr.Column():
|
|
@@ -31,3 +52,4 @@ with gr.Blocks() as demo:
|
|
| 31 |
|
| 32 |
demo.queue(concurrency_count=1)
|
| 33 |
demo.launch(debug=True, inline=True)
|
|
|
|
|
|
| 2 |
import bpy
|
| 3 |
import tempfile
|
| 4 |
|
| 5 |
+
def enable_GPUS():
|
| 6 |
+
bpy.data.scenes[0].render.engine = "CYCLES" #"CYCLES"
|
| 7 |
+
# Set the device_type
|
| 8 |
+
bpy.context.preferences.addons[
|
| 9 |
+
"cycles"
|
| 10 |
+
].preferences.compute_device_type = "CUDA" # or "OPENCL"
|
| 11 |
+
|
| 12 |
+
# Set the device and feature set
|
| 13 |
+
bpy.context.scene.cycles.device = "GPU"
|
| 14 |
+
|
| 15 |
+
for scene in bpy.data.scenes:
|
| 16 |
+
scene.cycles.device = "GPU"
|
| 17 |
+
|
| 18 |
+
bpy.context.preferences.addons["cycles"].preferences.get_devices()
|
| 19 |
+
print(bpy.context.preferences.addons["cycles"].preferences.compute_device_type)
|
| 20 |
+
for d in bpy.context.preferences.addons["cycles"].preferences.devices:
|
| 21 |
+
d["use"] = True # Using all devices, include GPU and CPU
|
| 22 |
+
print(d["name"])
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
|
| 27 |
def generate():
|
| 28 |
with tempfile.NamedTemporaryFile(suffix=".JPEG", delete=False) as f:
|
|
|
|
| 30 |
bpy.context.scene.render.resolution_x = 400
|
| 31 |
bpy.context.scene.render.image_settings.file_format = "JPEG"
|
| 32 |
bpy.context.scene.render.filepath = f.name
|
| 33 |
+
enable_GPUS()
|
| 34 |
bpy.ops.render.render(animation=False, write_still=True)
|
| 35 |
bpy.data.images["Render Result"].save_render(
|
| 36 |
filepath=bpy.context.scene.render.filepath
|
|
|
|
| 38 |
bpy.app.handlers.render_stats.clear()
|
| 39 |
return f.name
|
| 40 |
|
|
|
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column():
|
|
|
|
| 52 |
|
| 53 |
demo.queue(concurrency_count=1)
|
| 54 |
demo.launch(debug=True, inline=True)
|
| 55 |
+
w
|