Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_option problem #9

Open
erwanito12 opened this issue Aug 30, 2022 · 9 comments
Open

set_option problem #9

erwanito12 opened this issue Aug 30, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@erwanito12
Copy link

erwanito12 commented Aug 30, 2022

hello, with this script I am trying to display the output of the slider block in a result block without result. what is wrong with my script? thanks in advance

from barfi import st_barfi, barfi_schemas, Block
import streamlit as st

slider_block = Block(name='Slider')

slider_block.add_input()
slider_block.add_output()
slider_block.add_option(name='display-option', type='display',value='This is a Block with Slider option.')
slider_block.add_option(name='slider-option-1', type='slider', min=0, max=10, value=2.5)

def slider_block_func(self):
input_1_value = self.get_interface(name='Input 1')

slider_1_value = self.get_option(name='slider-option-1')

self.set_interface(name='Output 1', value=slider_1_value)

slider_block.add_compute(slider_block_func)

result = Block(name='Result')
result.add_input()
result.add_option(name='ValueText', type='display', value='toto')

def result_func(self):
in_1 = self.get_interface(name='Input 1')
self.set_option(name='ValueText',value=str(in_1))
result.add_compute(result_func)

compute_engine = st.checkbox('Activate barfi compute engine', value=True)
barfi_result = st_barfi(base_blocks=[ slider_block, result])
if barfi_result:
st.write(barfi_result)

@erwanito12
Copy link
Author

erwanito12 commented Aug 30, 2022

I want to reproduce this example:

export const DisplayNode = new NodeBuilder("DisplayNode")
.setName("Display")
.addInputInterface("Value")
.addOption("ValueText", "TextOption")

.onCalculate(n => {
    let value = n.getInterface("Value").value;

    n.setOptionValue("ValueText", value);
})
.build();

import { Node } from "@baklavajs/core";

export class MathNode extends Node {
constructor() {
super();
this.type = "MathNode";
this.name = "Math";
this.addInputInterface("Number 1", "SliderOption", 100);

    this.addOutputInterface("Result");
}

calculate() {
    const n1 = this.getInterface("Number 1").value;
   
    this.getInterface("Result").value = n1;
}

}

@krish-adi
Copy link
Owner

krish-adi commented Aug 30, 2022

Hello @erwanito12

If I understood you right, you want to display the value from the slider on the result block, updating the string toto to that value.

Then, that is not possible at the moment. (Nor do I see that feature in the roadmap.) The display option is on the initial block creation. And cannot be updated later on schema execution.

But you can get the result from the result block and display it on the app, by using:

if barfi_result:
    st.write(barfi_result['Result-1']['block'].get_interface('Input 1'))

Screenshot 2022-08-30 at 23 32 25

@erwanito12
Copy link
Author

Thank you @krish-adi for your detailed answer, you understood my request very well. my more general idea is to be able to add options to your library. I achieved this by modifying the files in the frontEnd folder and at option_builder.py. I want to be able to modify a canvas like I do with baklavajs. indeed the value cannot be updated within the framework of your library, it's a real shame that it greatly limits the use and ergonomics of your library. congratulations for your excellent work.

image

@erwanito12
Copy link
Author

which gives as result:

image

@erwanito12
Copy link
Author

with this script:

from barfi import st_barfi, barfi_schemas, Block
import streamlit as st

feed = Block(name='Feed')
feed.add_input()
feed.add_option(name = 'Peak', type = 'PeakOption', value=0.4)

def feed_func(self):

input_1_value = self.get_interface(name='Input 1')
self.set_option(name='Peak', value=input_1_value)

feed.add_compute(feed_func)

slider_block = Block(name='Slider')

slider_block.add_input()
slider_block.add_output()

slider_block.add_option(name='display-option', type='display',value='This is a Block with Slider option.')
slider_block.add_option(name='slider-option-1', type='slider', min=0, max=10, value=2.5)

def slider_block_func(self):
input_1_value = self.get_interface(name='Input 1')
slider_1_value = self.get_option(name='slider-option-1')
self.set_interface(name='Output 1', value=slider_1_value)
slider_block.add_compute(slider_block_func)

result = Block(name='Result')
result.add_input()
result.add_option(name='ValueText', type='display')

def result_func(self):
in_1 = self.get_interface(name='Input 1')
self.set_option(name='ValueText',value=str(in_1))
result.add_compute(result_func)

result.set_option(name='ValueText',value='toto')
compute_engine = st.checkbox('Activate barfi compute engine', value=True)
barfi_result = st_barfi(base_blocks=[ feed, slider_block, result])
if barfi_result:
st.write(barfi_result['Result-1']['block'].get_interface('Input 1'))

@osi1880vr
Copy link

hey erwanito12 would you mind to share your scripts? I like to play with this too as we got the same requirements. We like to build a block which could show a result image or maybe more

@krish-adi
Copy link
Owner

@erwanito12 Sorry, I missed this. Could you send a PR with an example to test it?

@restructai
Copy link

can i add a dialog box popup to add a form in the block

@Sendery
Copy link

Sendery commented Oct 20, 2023

I'm also looking forward for a way on how to update (rerender) a Display in the canvas
and add a feature for dobule click in a block and open a modal with maibe the str method of the block or a custom modal without rerun the streamlit.

Lovely and simple module/widget great work anyway

@krish-adi krish-adi added the enhancement New feature or request label Jan 15, 2025
@krish-adi krish-adi self-assigned this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants