Comments (4)
Hi @balaji-ramk thanks for the suggestion! We've recently added gr.render
, which offers a way to build dynamic apps and is a more flexible API, please take a look here: https://www.gradio.app/guides/dynamic-apps-with-render-decorator
from gradio.
Hi, thanks a ton, this looks very useful, and I'll definitely try it out!
Also thanks for taking the time to reply!
PS after snooping throught the documentation and trying it out a bit, I've found that there isn't a way to store the outputs of this render block into a specific variable that can be used in future functions, see the below code:
import gradio as gr
import time
with gr.Blocks() as demo:
with gr.Row():
num1 = gr.Textbox()
num2 = gr.Textbox()
result_btn = gr.Button("Add")
@gr.render(inputs=[num1, num2], triggers=[result_btn.click])
def show_outputs(num1, num2):
time.sleep(5)
result_value = gr.Textbox(str(int(num1) + int(num2)))
return result_value
multiply_btn = gr.Button("Double")
@gr.render(inputs=[result_value], triggers=[multiply_btn.click])
def double_output(num):
time.sleep(5)
doubled = gr.Textbox(2 * int(num))
demo.launch()
Would suggest adding an outputs parameter to the render block to fix this, but doing so could lead to something like this:
import gradio as gr
import time
with gr.Blocks() as demo:
with gr.Row():
num1 = gr.Textbox()
num2 = gr.Textbox()
result_btn = gr.Button("Add")
result_value = gr.Textbox(visible=False)
@gr.render(inputs=[num1, num2], triggers=[result_btn.click], outputs=[result_value, result_value])
def show_outputs(num1, num2):
time.sleep(5)
result_value = gr.Textbox(str(int(num1) + int(num2)))
return result_value, gr.update(visible=True)
multiply_btn = gr.Button("Double")
multiply_value = gr.Textbox(visible=False)
@gr.render(inputs=[result_value], triggers=[multiply_btn.click], outputs=[multiply_value, multiply_value])
def double_output(num):
time.sleep(5)
doubled = gr.Textbox(2 * int(num))
return doubled, gr.update(visible=False)
demo.launch()
Because of this limitation, I don't think this is a perfect solution to what I was looking for, as most of my workflows using gradio require this information to flow between modules, which this doesn't work for, as far as I can see.
Please do let me know if I am missing something, thanks a ton!
from gradio.
Hi @abidlabs I think I forgot to mention so don't know if you received a notification for this,
Sorry if this is spam, I'm not too sure how GitHub Issues work
from gradio.
Thanks for following up @balaji-ramk --
PS after snooping throught the documentation and trying it out a bit, I've found that there isn't a way to store the outputs of this render block into a specific variable that can be used in future functions, see the below code:
It is possible to use the rendered components directly in event triggers, as long as the events are defined inside of the render function. Here's an example:
import gradio as gr
with gr.Blocks() as demo:
text_count = gr.State(1)
add_btn = gr.Button("Add Box")
add_btn.click(lambda x: x + 1, text_count, text_count)
@gr.render(inputs=text_count)
def render_count(count):
boxes = []
for i in range(count):
box = gr.Textbox(key=i, label=f"Box {i}")
boxes.append(box)
def merge(*args):
return " ".join(args)
merge_btn.click(merge, boxes, output)
merge_btn = gr.Button("Merge")
output = gr.Textbox(label="Merged Output")
demo.launch()
from gradio.
Related Issues (20)
- Interface() show_progress doesn't work
- #8906 still not solve audio play out high delay
- Cannot separate State between users for public spaces accessing private spaces HOT 1
- Mermaid support in markdown for chatbot HOT 1
- "Use via API" with Bash returns an incorrect file download path HOT 2
- Enhancements to tool use in `gr.Chatbot` HOT 6
- gr.ImageEditor color picker is not working HOT 1
- `gr.Plot` is resized indefinitely when using a custom CSS HOT 1
- error 404: Session not found when configured with two upstream servers in nginx configuration HOT 4
- gradio cc build returns 0 even if frontend build is unsuccessful HOT 2
- Gradio Client use modern javascript that isn't always compatible HOT 1
- HuggingFaceDatasetSaver._deserialize_components raises OSError filename too long
- let image in gr.Image just fit inside the image container HOT 1
- `Chatbot` with `ChatMessage` with `metadata.title` is shown as collapsed accordion HOT 6
- update gr.Examples component,get an error which is list index out of range.
- Chat Interface - Adding additional params or inputs for use in function HOT 1
- gr.DownloadButton cannot get the correct filename HOT 2
- Cannot a remove/attachments HOT 1
- ValueError: MultimodalTextbox expects a dictionary with optional keys HOT 1
- gr.HTML Not Supported in description Argument of gradio.Interface HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradio.