0

(Python 3.11) I was trying to read a Blender file in Gradio, but something weird happened that I can't understand. Here is a simplified version of the problem I met today: When I try to run this code in gradio, I got error:

import gradio as gr
import bpy

blend_filepath = "/root/shiki/testp.blend"



## bpy.ops.wm.open_mainfile(filepath=blend_filepath)

def read():
    bpy.ops.wm.open_mainfile(filepath=blend_filepath)
    fps = str(bpy.context.scene.render.fps)
    res = str(bpy.context.scene.render.resolution_x) + "*" + str(bpy.context.scene.render.resolution_y)
    info = "FrameRate: " + fps + "\n" + "Resolution: " + res
    return info



with gr.Blocks() as demo:
    read_blend_file = gr.Button("Read Your Blender File")
    file_info_box = gr.Textbox(label="File Info")
    
    read_blend_file.click(fn=read, outputs=file_info_box)


demo.launch() 

error image

What made me confused is that, if I simply move bpy.ops.wm.open_mainfile(filepath=blend_filepath) out of function that triggered by Gradio button, the problem disappears. Does it means there's a conflict between Gradio and bpy?

import gradio as gr
import bpy

blend_filepath = "/root/shiki/testp.blend"



bpy.ops.wm.open_mainfile(filepath=blend_filepath)

def read():
    ## bpy.ops.wm.open_mainfile(filepath=blend_filepath)
    fps = str(bpy.context.scene.render.fps)
    res = str(bpy.context.scene.render.resolution_x) + "*" + str(bpy.context.scene.render.resolution_y)
    info = "FrameRate: " + fps + "\n" + "Resolution: " + res
    return info



with gr.Blocks() as demo:
    read_blend_file = gr.Button("Read Your Blender File")
    file_info_box = gr.Textbox(label="File Info")
    
    read_blend_file.click(fn=read, outputs=file_info_box)


demo.launch() 

error disappear

About crash logs: In Linux (bpy as python3.11 module):

root@mypc:~/shiki# python test.py 
                        * Running on local URL:  http://127.0.0.1:7860
                        To create a public link, set `share=True` in `launch()`.
                        Read blend: "/root/shiki/testp.blend"
                        Segmentation fault (core dumped)

No crash file generated in this case.

In Windows (run test.py in blender):

* Running on local URL:  http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Read blend: "C:\Users\Shiki\Desktop\TmpRender\tst.blend"

Error: EXCEPTION_ACCESS_VIOLATION
Address: 0x00007FF75E9C9270
Module: blender.exe
Thread: 0004e28c
Writing: C:\Users\Shiki\AppData\Local\Temp\script.crash.txt

script.crash.txt

2
  • Hi, could you include the full error log or traceback? This additional detail will make it easier to identify the issue and provide a more accurate solution. Thanks! Commented Nov 2, 2024 at 5:37
  • Thanks for reminding me that, I added the crash log just now (but crash log only generated in Windows, as in Linux it just crashed without any info, I don't know the reason.) Commented Nov 2, 2024 at 16:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.