forked from gradio-app/gradio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
491 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import gradio as gr | ||
|
||
|
||
def change_textbox(choice): | ||
if choice == "short": | ||
return gr.update(lines=2, visible=True) | ||
return gr.update(lines=2, visible=True, value="Short story: ") | ||
elif choice == "long": | ||
return gr.update(lines=8, visible=True) | ||
return gr.update(lines=8, visible=True, value="Long story...") | ||
else: | ||
return gr.update(visible=False) | ||
|
||
|
||
with gr.Blocks() as demo: | ||
radio = gr.Radio( | ||
["short", "long", "none"], label="What kind of essay would you like to write?" | ||
["short", "long", "none"], label="Essay Length to Write?" | ||
) | ||
text = gr.Textbox(lines=2, interactive=True) | ||
|
||
radio.change(fn=change_textbox, inputs=radio, outputs=text) | ||
|
||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import gradio as gr | ||
|
||
|
||
def update(name): | ||
def welcome(name): | ||
return f"Welcome to Gradio, {name}!" | ||
|
||
demo = gr.Blocks() | ||
|
||
with demo: | ||
with gr.Blocks() as demo: | ||
gr.Markdown( | ||
""" | ||
# Hello World! | ||
Start typing below to see the output. | ||
""") | ||
inp = gr.Textbox(placeholder="What is your name?") | ||
out = gr.Textbox() | ||
|
||
inp.change(fn=update, | ||
inputs=inp, | ||
outputs=out) | ||
inp.change(welcome, inp, out) | ||
|
||
demo.launch() | ||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import gradio as gr | ||
|
||
def greet(name): | ||
return "Hello " + name + "!" | ||
|
||
with gr.Blocks() as demo: | ||
name = gr.Textbox(label="Name") | ||
output = gr.Textbox(label="Output Box") | ||
greet_btn = gr.Button("Greet") | ||
greet_btn.click(fn=greet, inputs=name, outputs=output) | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import gradio as gr | ||
|
||
|
||
def greet(name): | ||
return "Hello " + name + "!!" | ||
return "Hello " + name + "!" | ||
|
||
demo = gr.Interface(fn=greet, inputs="text", outputs="text") | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import gradio as gr | ||
|
||
|
||
def greet(name): | ||
return "Hello " + name + "!" | ||
|
||
|
||
demo = gr.Interface( | ||
fn=greet, | ||
inputs=gr.Textbox(lines=2, placeholder="Name Here..."), | ||
outputs="text", | ||
) | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import gradio as gr | ||
|
||
def increase(num): | ||
return num + 1 | ||
|
||
with gr.Blocks() as demo: | ||
a = gr.Number(label="a") | ||
b = gr.Number(label="b") | ||
btoa = gr.Button("a > b") | ||
atob = gr.Button("b > a") | ||
atob.click(increase, a, b) | ||
btoa.click(increase, b, a) | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import gradio as gr | ||
|
||
scores = [] | ||
|
||
def track_score(score): | ||
scores.append(score) | ||
top_scores = sorted(scores, reverse=True)[:3] | ||
return top_scores | ||
|
||
demo = gr.Interface( | ||
track_score, | ||
gr.Number(label="Score"), | ||
gr.JSON(label="Top Scores") | ||
) | ||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import numpy as np | ||
|
||
import gradio as gr | ||
|
||
|
||
def sepia(input_img): | ||
sepia_filter = np.array( | ||
[[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]] | ||
) | ||
sepia_filter = np.array([ | ||
[0.393, 0.769, 0.189], | ||
[0.349, 0.686, 0.168], | ||
[0.272, 0.534, 0.131] | ||
]) | ||
sepia_img = input_img.dot(sepia_filter.T) | ||
sepia_img /= sepia_img.max() | ||
return sepia_img | ||
|
||
|
||
demo = gr.Interface(sepia, gr.Image(shape=(200, 200)), "image") | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import gradio as gr | ||
import numpy as np | ||
|
||
with gr.Blocks() as demo: | ||
inp = gr.Image(source="webcam") | ||
out = gr.Image() | ||
|
||
def flip(im): | ||
return np.flipud(im) | ||
inp.stream(flip, [inp], [out]) | ||
def flip(im): | ||
return np.flipud(im) | ||
|
||
demo = gr.Interface( | ||
flip, | ||
gr.Image(source="webcam", streaming=True), | ||
"image", | ||
live=True | ||
) | ||
if __name__ == "__main__": | ||
demo.launch() |
Oops, something went wrong.