krish-adi / barfi Goto Github PK
View Code? Open in Web Editor NEWPython Flow Based Programming environment that provides a graphical programming environment.
Home Page: https://barfi.readthedocs.io
License: MIT License
Python Flow Based Programming environment that provides a graphical programming environment.
Home Page: https://barfi.readthedocs.io
License: MIT License
In option_builder (https://github.com/krish-adi/barfi/blob/main/barfi/option_builder.py), the build_option function sets the option and valid types.
When we associate a function to a block e.g.
my_function_name(self):
do_something
my_block.add_compute(my_function_name)
There is no way to pass custom params to the associated function that are not exposed to the user. It's beneficial to be able to pass params to the block's associated function without exposing them to the user.
If we try to do something like add a new param e.g.
my_function_name(self, my_custom_param):
do_something
my_block.add_compute(my_function_name(my_custom_param=my_custom_param))
It won't work because there's no way to provide for both self and my_custom_param.
There are several use cases for this but one is using the streamlit session_state and modifying it based upon which block is running.
Let's say we want a message (streamlit.info) that shows users which block is currently running. We can pass the session state to each block's function and modify the message to output which block is running. This is helpful for blocks with long running tasks and general error messaging to the user when something went wrong.
How can we configure node background color and interface colors when define a Block?
Hello,
I'm considering the use of your lib, but i would like to be able to add decorators to the inputs/outputs to have types,
like integer / String / other and to only be able to do connection if the input / output have matching types.
The types could be visually identified by changing the color of the connection dot or something like this.
Do you think it's feasible maybe i can get into the adjustement my self, but i would need some guidance in your code to do it properly (i currently didn't take time to dig in the code too much).
Best regards
Currently the schemas saved from the widget on streamlit ends up in the root of the application and itsnt customizeable. It would be great if we could configure a prefix for this path with the default option being the root of the application.
For user error messages (i.e. which block failed) and other uses
For the st.text_input widget, streamlit supports password masking using the type='password' param (https://docs.streamlit.io/library/api-reference/widgets/st.text_input). Any way to get support for this?
It would be wonderful to try baklavajs v2, which is now in beta. Would it be possible to create a branch of barfi that is updated to work with baklavajs v2? There are some nice features like subgrouping that would be very helpful.
Here is the beta announcement:
newcat/baklavajs#219
many thanks!
Is there an option for hidden inputs or outputs? meaning a default input/output that is carried down each block without the user interaction?
Love the new feature with block categorization - everything works as expected until you hit the Execute button.
To Re-Create:
Versions:
relative code:
base_blocks = [logic_filter, to_dataframe, use_cached_data, save_to_cache, barchart_output, excel_output]
base_blocks_category = {
'Logic and Filter Blocks': [logic_filter],
'Data Conversion Blocks': [to_dataframe],
'Input Blocks':[use_cached_data],
'Output Blocks':[json_output, excel_output, barchart_output, save_to_cache]
}
barfi_result = st_barfi(
base_blocks=base_blocks_category,
compute_engine=True,
load_schema=load_schema)
Error
File "/Users/zach.brewer/Dev/pythonprojects/.virtualenvs/test-nodepython/lib/python3.8/site-packages/barfi/__init__.py", line 87, in st_barfi
_ce._map_block_link()
File "/Users/zach.brewer/Dev/pythonprojects/.virtualenvs/test-nodepython/lib/python3.8/site-packages/barfi/compute_engine.py", line 47, in _map_block_link
_parent_block = next(
File "/Users/zach.brewer/Dev/pythonprojects/.virtualenvs/test-nodepython/lib/python3.8/site-packages/barfi/compute_engine.py", line 48, in <genexpr>
_b for _b in self._blocks if _b._type == _block['type'])
AttributeError: 'str' object has no attribute '_type'
In my testing I have many schemas and needed a way to allow users to delete and manage schemas without coding.
Schemas get somewhat unwieldy if there are many in barfi.schema. I have a multi-page streamlit app (barfi is the first page) and one of the other pages is a schema manager that utilizes barfi's schema_loader.py to allow users to view, add, or clone existing pickled schemas in the schemas.barfi file. I could write my own utility module but I'm using barfi's own schema loader functions since they already manage schema.barfi.
You don't have a contribution guide in this repo so I am adding the code here instead of making a pull request.
def delete_schema(schema_name: str):
try:
with open('schemas.barfi', 'rb') as handle_read:
schemas = pickle.load(handle_read)
except FileNotFoundError:
schemas = {}
if schema_name in schemas:
del schemas[schema_name]
else:
raise ValueError(
f'Schema :{schema_name}: not found in the saved schemas')
with open('schemas.barfi', 'wb') as handle_write:
pickle.dump(schemas, handle_write, protocol=pickle.HIGHEST_PROTOCOL)
Hi. Thanks for the great product.
Does Barfi support asynchronous execution?
As far as I have tried, all nodes seem to be executed in sequence.
if there are many nodes to select from, a filter will be required.
The submenu for new blocks gets really long if you have quite a few blocks. Wondering if it is possible to categorize blocks so that in the JS frontend when you create a new block, you see the main category and then the blocks that fall under that specific category.
I would like to be able to set the size of the editorCanvas. I was not able to overwrite the css with the st.markdown st.write unsafe_html trick.
i already tried on multiple browsers but they don't show ,but they appear in the minimap on upper right
`saved_schemas = barfi_schemas()
select_schema = st.selectbox('Select a saved schema:', saved_schemas)
feed = Block(name='Feed')
feed.add_output()
result = Block(name='Result')
result.add_input()
barfi_result = st_barfi(base_blocks= [feed, result],load_schema= select_schema)`
but they show witouth problem when i simply do
barfi_result = st_barfi(base_blocks= [feed, result])
this happen even with the examples
Hey krish-adi,
would it be thinkable to have a decoupled version of barfi with no strings attached to streamlit or nodejs?
I understand there is the backend which need to be present in some way, how you would document the backend API and one could setup his own backend? Once the build backend is working it could be shared too, maybe that way more implementations show up.
We try to use your or any similar system but they all come bound to some kind of a server which I dont need or dont like. I would like to have a totaly open system where I could implement my own backend. Yes thats additional work on my side but at least I would have more control about how and where I implement the system. Like there is a way to have a browser only barfi but the backend has to be build by providing APIs which provide what ever barfi needs in the backend to work.
Sounds weired but might be an idea after all ;)
Thanks for your time and also thanks for all the effort you spend building barfi, we already have plenty of fun with it even with the "limitations" of being nailed to use streamlit for now.
Cheers
Werner
Hi!
I've started using barfi in streamlit with stable diffusion. It will be a great tool for node based ai generation I think.
I have a few things I'm missing, and wondering if it was possible to implement the following:
Image/Video output on the node, slider step adjustment.
Also, id like cycles. Do you have a recommendation how it would be possible?
I have built a quick function that would stop my iterations when goal is reached. In my understanding its the id's that are problematic, but we could check for "first and last" blocks, and increment id's when a loop is reached. What do you think?
First ones to occur, but surely more to come. : ))
Looks like we are going to use it very intensly, given, some features can be updated : )
Hi. Barfi looks really cool.
I'm trying to let user edit a workflow - how statuses can change for specific job - without any computations, just a graph. Don't really like graphviz (noninteractive and ugly). Thought to try Barfi for this. I'd appreciate a few answers. Docs look a little bit limited. Is it possible to make blocks with any number of input/output connections (well, just a list), so that user could interconnect them however they want? Also, can graphs be cyclic without computations.
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)
It is impossible, or very difficult, to change the styling of Barfi to fit a specific project.
For example, I wanted to remove the Menu and Execute buttons using css because they don't fit the functionality of my program, but the Barfi graph is locked behind an iframe and I could not find a way around it.
I propose that a new parameter, style
, should be added to bf.st_barfi
, which is a string of css that is inserted into the iframe (I don't know how this would be done, or if it is feasible).
The below example would create a Barfi graph where the color of the backgrounds of the nodes are red.
bf.st_barfi(
[],
style="""
.node > .__content {
background: red;
}
""",
)
Use Poetry to manage the package and use poetry install
to run the package with the environment in editable mode.
Creating cyclical connections between nodes raises a TypeError because raise
is invoked with a str, rather than an Exception. A custom Exception should be used for this.
Minimum Reproducing Project - https://github.com/GsLogiMaker/barfi_error_minimal_project/releases/tag/v0.0.0
Hey @krish-adi ,
The package was really helpful,
I think it will be help full to add more details on classes
I had hard time finding it from code
Thank you so much for open source. Would you like to ask, after this project has created two blocks, can you use code to connect the two blocks? Or do you have to drag the wire manually?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.