Add Gradio models

This commit is contained in:
Sylwia Budzynska
2024-04-05 14:14:21 +02:00
parent c378d6a661
commit bed0d5678d
5 changed files with 190 additions and 0 deletions

View File

@@ -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()

View File

@@ -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()