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

请教下sam_dummy_component这个当做前后端传值的组件,大概的原理是怎样的 #174

Open
lijun4017 opened this issue Nov 25, 2023 · 1 comment

Comments

@lijun4017
Copy link

lijun4017 commented Nov 25, 2023

大佬好,感谢你做的贡献。
我再研究你的源码的过程中发现一个点搞不明白,特来请教。
sam.py中你使用了sam_dummy_component = gr.Label(visible=False)这个组件,我大概猜到这个应该是用来存在鼠标点击标注正向和反向两个数组的。
然后再一下点击事件中把sam_dummy_component作为sam_predict函数的参数
sam_submit.click(
fn=sam_predict,
_js='submit_sam',
inputs=[sam_model_name, sam_input_image, # SAM
sam_dummy_component, sam_dummy_component, # Point prompts
dino_checkbox, dino_model_name, dino_text_prompt, dino_box_threshold, # DINO prompts
dino_preview_checkbox, dino_preview_boxes_selection], # DINO preview prompts

这里我有2个地方不太明白

1)sam_dummy_component这个组件既作为标注正向参数,也作为标注反向参数,但是我再JS中找不到对应的赋值,只能找到samTabPrefix() + "positive" 和samTabPrefix() + "negative"的赋值,想不明白这个和sam_dummy_component是怎样建立关系的。

2)我把你的代码sam.js和sam.py自己复制一份,且简化了sam.py,独立于stablediffusion运行的单个程序,调用stablediffusion的API来运行,其中一切都正常,但是sam_dummy_component这个传参这里出问题了,在我自定义的sam_predict函数中,接受到negative_points是正常,但是positive_points是空的

盼回复,感谢。

@lijun4017
Copy link
Author

我问题已经解决了,在sam.js中function submit_sam() 的 res[2] = positive_points; res[3] = negative_points; 改为res[1] = positive_points; res[2] = negative_points; ,值就对了。但是我依然不知道这里的原理。我猜是客户端组装的这个res参数,应该是gradio自己能直接读的到,无需编码。有懂的大神希望解答。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant