include demos as documentation

This commit is contained in:
Ali Abid 2020-08-21 14:20:05 -07:00
parent 926eccbdc9
commit efb2233723
28 changed files with 31 additions and 13 deletions

View File

@ -1,3 +1,5 @@
# Demo: (Textbox, Textbox) -> (HighlightedText)
import gradio as gr
from difflib import Differ

View File

@ -1,3 +1,5 @@
# Demo: (Image) -> (Label)
import tensorflow as tf
import gradio
import os
@ -16,7 +18,7 @@ def recognize_digit(image):
gr.Interface(
recognize_digit,
gradio.inputs.Image(shape=(28, 28), image_mode="L", source="canvas"),
"sketchpad",
gradio.outputs.Label(num_top_classes=3),
live=True,
capture_session=True,

View File

@ -1,3 +1,5 @@
# Demo (Dataframe, Dropdown) -> (Dataframe)
import gradio as gr
import numpy as np
import random

View File

@ -1,3 +1,5 @@
# Demo: (Dropdown, Slider, Textbox) -> (Audio)
import gradio as gr
import numpy as np
import random
@ -8,6 +10,7 @@ def generate_tone(note, octave, duration):
sr = 48000
a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
frequency = a4_freq * 2 ** (tones_from_a4 / 12)
duration = int(duration)
audio = np.linspace(0, duration, duration * sr)
audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
return (sr, audio)

View File

@ -1,18 +1,17 @@
# Demo: (Image) -> (Image)
import gradio as gr
from time import time
from PIL import Image, ImageFilter
from PIL import Image
def image_mod(image):
return image.rotate(45), image.filter(ImageFilter.FIND_EDGES)
return image.rotate(45)
gr.Interface(image_mod,
gr.inputs.Image(type="pil"),
[
gr.outputs.Image(type="pil"),
gr.outputs.Image(type="pil"),
],
gr.outputs.Image(type="pil"),
examples=[
["images/cheetah1.jpg"],
["images/cheetah2.jpg"],

View File

@ -1,9 +1,10 @@
# Demo: (Dataframe) -> (Dataframe)
import gradio as gr
import numpy as np
import random
def transpose(matrix):
print(matrix)
return matrix.T
gr.Interface(transpose,

View File

@ -1,3 +1,5 @@
# Demo: (Audio) -> (Audio)
import gradio as gr
import numpy as np
import random

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

@ -1,3 +1,5 @@
# Demo: (Slider, Dropdown, Radio, CheckboxGroup, Checkbox) -> (Textbox)
import gradio as gr
import numpy as np

View File

@ -1,3 +1,5 @@
# Demo: (Audio) -> (Image)
import gradio as gr
import matplotlib.pyplot as plt
import numpy as np
@ -5,13 +7,12 @@ from scipy import signal
from scipy.io import wavfile
def reverse_audio(audio):
def spectrogram(audio):
sr, data = audio
data = np.delete(data, 1, 1).reshape(-1)
frequencies, times, spectrogram = signal.spectrogram(data.reshape(-1), sr, window="hamming")
plt.pcolormesh(times, frequencies, np.log10(spectrogram))
frequencies, times, spectrogram_data = signal.spectrogram(data.reshape(-1), sr, window="hamming")
plt.pcolormesh(times, frequencies, np.log10(spectrogram_data))
return plt
gr.Interface(reverse_audio, "audio", "plot").launch()
gr.Interface(spectrogram, "audio", "plot").launch()

View File

@ -1,3 +1,5 @@
# (Radio, CheckboxGroup, Slider, Dropdown) -> (Image)
import gradio as gr
import random
import matplotlib.pyplot as plt

View File

@ -1,3 +1,5 @@
# Demo: (Textbox) -> (HighlightedText, KeyValues, HTML)
import spacy
from spacy import displacy
import gradio as gr

Binary file not shown.