Coder Social home page Coder Social logo

Comments (2)

abidlabs avatar abidlabs commented on August 16, 2024

Hi @edgarGracia yes this is intentional, you can only provide a function when instantiating the component, otherwise you will need to provide the function in the click() event and then provide every there as well. So you would need to do:

import gradio as gr
import numpy as np


def get_random_img():
    return (np.random.random((512,512,3)) * 255).astype("uint8")


def set_gr_image():
    return gr.Image(get_random_img, width=512, height=512)


with gr.Blocks() as demo:
    button.click(get_random_img, outputs=gr_image, every=1)  # should work

demo.launch()

If you cannot do this, the alternative would be to convert set_gr_image() to be an iterator, e.g.

import gradio as gr
import numpy as np


def get_random_img():
    return (np.random.random((512,512,3)) * 255).astype("uint8")


def set_gr_image():
    while True:  # something like this
        yield get_random_img()
        time.sleep(1)



with gr.Blocks() as demo:
    button.click(set_gr_image, outputs=gr_image)  # should work

demo.launch()

from gradio.

edgarGracia avatar edgarGracia commented on August 16, 2024

Hi @abidlabs, thanks for you quick response, this solves my issue!

from gradio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.