mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Add Gradio models
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import gradio as gr
|
||||
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
name = gr.Textbox(label="Name")
|
||||
output = gr.Textbox(label="Output Box")
|
||||
greet_btn = gr.Button("Hello")
|
||||
|
||||
# decorator
|
||||
@greet_btn.click(inputs=name, outputs=output)
|
||||
def greet(name):
|
||||
return "Hello " + name + "!"
|
||||
|
||||
# `click` event handler with keyword arguments
|
||||
def greet1(name):
|
||||
return "Hello " + name + "!"
|
||||
|
||||
greet1_btn = gr.Button("Hello")
|
||||
greet1_btn.click(fn=greet1, inputs=name, outputs=output, api_name="greet")
|
||||
|
||||
# `click` event handler with positional arguments
|
||||
def greet2(name):
|
||||
return "Hello " + name + "!"
|
||||
|
||||
greet2_btn = gr.Button("Hello")
|
||||
greet2_btn.click(fn=greet2, inputs=name, outputs=output, api_name="greet")
|
||||
|
||||
|
||||
demo.launch()
|
||||
@@ -0,0 +1,22 @@
|
||||
import gradio as gr
|
||||
import os
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
path = gr.Textbox(label="Path")
|
||||
file = gr.Textbox(label="File")
|
||||
output = gr.Textbox(label="Output Box")
|
||||
|
||||
|
||||
# path injection sink
|
||||
def fileread(path, file):
|
||||
filepath = os.path.join(path, file)
|
||||
with open(filepath, "r") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
# `click` event handler with `inputs` containing a list
|
||||
greet1_btn = gr.Button("Path for the file to display")
|
||||
greet1_btn.click(fn=fileread, inputs=[path,file], outputs=output, api_name="fileread")
|
||||
|
||||
|
||||
demo.launch()
|
||||
Reference in New Issue
Block a user