gradio icon indicating copy to clipboard operation
gradio copied to clipboard

How to make_ JS parameter references JS file?

Open tt0203 opened this issue 1 year ago • 4 comments

I see that the cases provided on the official website are only the cases where the arrow function defines variables and returns. However, how to implement a custom function by referencing an online JS file?

Just i have an online JS file: https://huggingface.co/spaces/changxin/test/raw/main/statics/md5.js How can I use the md5 function?

tt0203 avatar Aug 10 '22 06:08 tt0203

https://gradio.app/custom_CSS_and_JS/

tt0203 avatar Aug 10 '22 06:08 tt0203

Hi @tt0203, would you be able to give us more context around this issue? What is your Gradio code, and what does this md5 function do?

abidlabs avatar Aug 10 '22 12:08 abidlabs

@abidlabs

Now,I just try to use the following code:

import gradio as gr demo=gr.Blocks() with demo: with gr.Tabs(): with gr.TabItem("js"): gr.Markdown("# js处理测试") a=gr.Textbox(label='请输入需要js处理的字符串') js_output=gr.Textbox(label="JS输出") js_button=gr.Button("调用js引用") js_button.click(None,a,js_output,_js='(x)=>md5(x);') demo.launch()

I Want to implement the reference of MD5 function in JS file,but it doesn't work.

tt0203 avatar Aug 11 '22 00:08 tt0203

Hi@abidlabs

Now,I just try to use the following code:

import gradio as gr demo=gr.Blocks() with demo: with gr.Tabs(): with gr.TabItem("js"): gr.Markdown("# js处理测试") a=gr.Textbox(label='请输入需要js处理的字符串') js_output=gr.Textbox(label="JS输出") js_button=gr.Button("调用js引用") js_button.click(None,a,js_output,_js='(x)=>md5(x);')

demo.launch()

I want to implement the reference of MD5 function in JS file,use md5 function to encrypt the gr.Textbox string,but it doesn't work.

tt0203 avatar Aug 11 '22 00:08 tt0203

Hi @tt0203, as I responded to your other issue, I believe you cannot access external javascript files from inside your Gradio app. This may change in the future (please track #2137), but at this moment we do not support it.

abidlabs avatar Sep 21 '22 19:09 abidlabs