gradio-app/gradio

AttributeError: 'Image' object has no attribute 'value'

Closed this issue · 2 comments

Describe the bug

I want to change the gradio.Image.value dynamically. But it seems like there is a little way to change the value.
I want to call a function in other files to actively change the gradio.Image.value in the main function.
You can find out that I rewrite the new function in class to make sure that targetImage's memory address will not change.
I pass a parameter which is image path and then the targetImage's value will change. In the main.py, everythin is fine. But in another file, I got an error which said that 'Image' object has no attribute 'value'.
I guess the reasaon is that gradio can't make a gradio.Image component in another file.
I need help, please.
Can gradio achieve the goal about dynamically changing image value?
Sorry for my poor English.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

#main.py
import gradio as gr
from block2 import gradioImage
frame_show =  gr.Image(value="path1", label="frameshowing", width= 200)
gradioImageClass=gradioImage(frame_show)
gradioImageClass.show_image('path2")
#block2.py
class gradioImage():
    __instance=None
    def __new__(cls, Image):
        if not cls.__instance:
            cls.__instance = super().__new__(cls)
            cls.__instance.targetImage = Image
        return cls.__instance
    @classmethod
    def show_image(cls, imagePath):
        middle_gradioImage = gr.Image(value=imagePath, visible=False)
        cls.__instance.targetImage.value = middle_gradioImage.value
#other file.py
from block2 import gradioImage
gradioImage.show_image("path3")

Screenshot

No response

Logs

Traceback (most recent call last):
    gradioImage.show_image("E:/AIResource/Image/digimon/86557814_p0_master1200.jpg")
   in show_image
    cls.__instance.targetImage.value = middle_gradioImage.value
AttributeError: 'Image' object has no attribute 'value'

System Info

win11
gradio 4.28.3

Severity

Hi @liuchangzong I'm really sorry but this issue is not very clear to me. I'm not sure what you're trying to do, or what the behavior you're seeing is. The code you've provided is also incomplete and not properly formatted, which makes it hard for me to follow the issue. Could you please edit the issue for clarity?

going to close this. we can reopen with a clearer issue