mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-18 10:44:33 +08:00
cleanup demos
This commit is contained in:
parent
eda553e0d7
commit
3c9bd18005
@ -21,5 +21,6 @@ iface = gr.Interface(calculator,
|
||||
[0, "subtract", 1.2],
|
||||
]
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
iface.launch()
|
||||
|
@ -11,7 +11,7 @@ def diff_texts(text1, text2):
|
||||
]
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
diff_texts,
|
||||
[
|
||||
gr.inputs.Textbox(lines=3, default="The quick brown fox jumped over the lazy dogs."),
|
||||
@ -23,7 +23,7 @@ io = gr.Interface(
|
||||
" ": "none",
|
||||
}))
|
||||
|
||||
io.test_launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
io.launch()
|
||||
|
@ -15,7 +15,7 @@ def recognize_digit(image):
|
||||
return {str(i): prediction[i] for i in range(10)}
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
recognize_digit,
|
||||
"sketchpad",
|
||||
gradio.outputs.Label(num_top_classes=3),
|
||||
@ -23,5 +23,8 @@ io = gr.Interface(
|
||||
capture_session=True,
|
||||
)
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
||||
|
@ -34,5 +34,6 @@ def segment_face(inp):
|
||||
|
||||
|
||||
iface = gr.Interface(segment_face, "webcam", "image", capture_session=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
@ -7,7 +7,7 @@ import random
|
||||
def filter_records(records, gender):
|
||||
return records[records['gender'] == gender]
|
||||
|
||||
io = gr.Interface(filter_records,
|
||||
iface = gr.Interface(filter_records,
|
||||
[
|
||||
gr.inputs.Dataframe(headers=["name", "age", "gender"], datatype=["str", "number", "str"], row_count=5),
|
||||
gr.inputs.Dropdown(["M", "F", "O"])
|
||||
@ -16,5 +16,8 @@ io = gr.Interface(filter_records,
|
||||
description="Enter gender as 'M', 'F', or 'O' for other."
|
||||
)
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
||||
|
@ -22,7 +22,7 @@ def plot_forecast(final_year, companies, noise, show_legend, point_style):
|
||||
return fig
|
||||
|
||||
|
||||
gr.Interface(plot_forecast,
|
||||
iface = gr.Interface(plot_forecast,
|
||||
[
|
||||
gr.inputs.Radio([2025, 2030, 2035, 2040],
|
||||
label="Project to:"),
|
||||
@ -33,4 +33,7 @@ gr.Interface(plot_forecast,
|
||||
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
|
||||
],
|
||||
gr.outputs.Image(plot=True, label="forecast")
|
||||
).launch()
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -16,7 +16,7 @@ def generate_tone(note, octave, duration):
|
||||
return sr, audio
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
generate_tone,
|
||||
[
|
||||
gr.inputs.Dropdown(notes, type="index"),
|
||||
@ -24,5 +24,6 @@ io = gr.Interface(
|
||||
gr.inputs.Textbox(type="number", default=1, label="Duration in seconds")
|
||||
], "audio")
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -8,9 +8,11 @@ from PIL import Image
|
||||
import requests
|
||||
from urllib.request import urlretrieve
|
||||
import json
|
||||
import os
|
||||
|
||||
# Load human-readable labels for ImageNet.
|
||||
with open("files/imagenet_labels.json") as labels_file:
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(os.path.join(current_dir, "files/imagenet_labels.json")) as labels_file:
|
||||
labels = json.load(labels_file)
|
||||
|
||||
mobile_net = tf.keras.applications.MobileNetV2()
|
||||
@ -26,7 +28,7 @@ def image_classifier(im):
|
||||
image = gr.inputs.Image(shape=(224, 224))
|
||||
label = gr.outputs.Label(num_top_classes=3)
|
||||
|
||||
io = gr.Interface(image_classifier, image, label,
|
||||
iface = gr.Interface(image_classifier, image, label,
|
||||
capture_session=True,
|
||||
interpretation="default",
|
||||
examples=[
|
||||
@ -34,4 +36,5 @@ io = gr.Interface(image_classifier, image, label,
|
||||
["images/lion.jpg"]
|
||||
])
|
||||
|
||||
io.launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -7,7 +7,7 @@ def image_mod(image):
|
||||
return image.rotate(45)
|
||||
|
||||
|
||||
io = gr.Interface(image_mod,
|
||||
iface = gr.Interface(image_mod,
|
||||
gr.inputs.Image(type="pil"),
|
||||
"image",
|
||||
examples=[
|
||||
@ -16,7 +16,7 @@ io = gr.Interface(image_mod,
|
||||
["images/lion.jpg"],
|
||||
])
|
||||
|
||||
io.test_launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
io.launch()
|
||||
iface.launch()
|
||||
|
@ -9,10 +9,10 @@ def longest_word(text):
|
||||
|
||||
ex = "The quick brown fox jumped over the lazy dog."
|
||||
|
||||
io = gr.Interface(longest_word, "textbox", "label",
|
||||
iface = gr.Interface(longest_word, "textbox", "label",
|
||||
interpretation="default", examples=[[ex]])
|
||||
|
||||
io.test_launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
io.launch()
|
||||
iface.launch()
|
||||
|
@ -37,7 +37,7 @@ def main_note(audio):
|
||||
volume_per_pitch[pitch] += 1.0 * volume / total_volume
|
||||
return volume_per_pitch
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
main_note,
|
||||
"microphone",
|
||||
gr.outputs.Label(num_top_classes=4),
|
||||
@ -47,4 +47,5 @@ io = gr.Interface(
|
||||
],
|
||||
interpretation="default")
|
||||
|
||||
io.launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -7,7 +7,7 @@ def transpose(matrix):
|
||||
return matrix.T
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
transpose,
|
||||
gr.inputs.Dataframe(type="numpy", datatype="number", row_count=5, col_count=3),
|
||||
"numpy",
|
||||
@ -20,7 +20,7 @@ io = gr.Interface(
|
||||
]
|
||||
)
|
||||
|
||||
io.test_launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
io.launch()
|
||||
iface.launch()
|
||||
|
@ -32,4 +32,4 @@ iface = gr.Interface(outbreak,
|
||||
],
|
||||
"plot")
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
iface.launch()
|
||||
|
@ -15,4 +15,4 @@ iface = gr.Interface(qa_func,
|
||||
],
|
||||
gr.outputs.Textbox(label="Answer"))
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
iface.launch()
|
||||
|
@ -9,7 +9,8 @@ def reverse_audio(audio):
|
||||
return (sr, np.flipud(data))
|
||||
|
||||
|
||||
io = gr.Interface(reverse_audio, "microphone", "audio")
|
||||
iface = gr.Interface(reverse_audio, "microphone", "audio")
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -6,7 +6,7 @@ def sentence_builder(quantity, animal, place, activity_list, morning):
|
||||
return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
sentence_builder,
|
||||
[
|
||||
gr.inputs.Slider(2, 20),
|
||||
@ -23,7 +23,7 @@ io = gr.Interface(
|
||||
[8, "cat", "zoo", ["ate"], True],
|
||||
])
|
||||
|
||||
io.test_launch()
|
||||
iface.test_launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
io.launch()
|
||||
iface.launch()
|
||||
|
@ -11,7 +11,8 @@ def sentiment_analysis(text):
|
||||
del scores["compound"]
|
||||
return scores
|
||||
|
||||
io = gr.Interface(sentiment_analysis, "textbox", "label", interpretation="default")
|
||||
iface = gr.Interface(sentiment_analysis, "textbox", "label", interpretation="default")
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -15,7 +15,8 @@ def spectrogram(audio):
|
||||
return plt
|
||||
|
||||
|
||||
io = gr.Interface(spectrogram, "audio", "plot")
|
||||
iface = gr.Interface(spectrogram, "audio", "plot")
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -23,7 +23,7 @@ def stock_forecast(final_year, companies, noise, show_legend, point_style):
|
||||
return fig
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
stock_forecast,
|
||||
[
|
||||
gr.inputs.Radio([2025, 2030, 2035, 2040], label="Project to:"),
|
||||
@ -33,5 +33,6 @@ io = gr.Interface(
|
||||
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style")],
|
||||
gr.outputs.Image(plot=True, label="forecast"))
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -25,7 +25,7 @@ def tax_calculator(income, marital_status, assets):
|
||||
|
||||
return round(total_tax)
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
tax_calculator,
|
||||
[
|
||||
"number",
|
||||
@ -44,4 +44,5 @@ io = gr.Interface(
|
||||
]
|
||||
)
|
||||
|
||||
io.launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -23,7 +23,7 @@ def text_analysis(text):
|
||||
return pos_tokens, pos_count, html
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
text_analysis,
|
||||
gr.inputs.Textbox(placeholder="Enter sentence here..."),
|
||||
[
|
||||
@ -35,5 +35,6 @@ io = gr.Interface(
|
||||
]
|
||||
)
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -8,8 +8,10 @@ from sklearn import preprocessing
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.ensemble import RandomForestClassifier
|
||||
from sklearn.metrics import accuracy_score
|
||||
import os
|
||||
|
||||
data = pd.read_csv('files/titanic.csv')
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
data = pd.read_csv(os.path.join(current_dir, 'files/titanic.csv'))
|
||||
|
||||
def encode_age(df):
|
||||
df.Age = df.Age.fillna(-0.5)
|
||||
@ -66,7 +68,7 @@ def predict_survival(passenger_class, is_male, age, company, fare, embark_point)
|
||||
pred = clf.predict_proba(df)[0]
|
||||
return {'Perishes': pred[0], 'Survives': pred[1]}
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
predict_survival,
|
||||
[
|
||||
gr.inputs.Dropdown(["first", "second", "third"], type="index"),
|
||||
@ -85,4 +87,5 @@ io = gr.Interface(
|
||||
interpretation="default"
|
||||
)
|
||||
|
||||
io.launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -8,7 +8,8 @@ def snap(image):
|
||||
return np.flipud(image)
|
||||
|
||||
|
||||
io = gr.Interface(snap, gr.inputs.Image(shape=(100,100), image_mode="L", source="webcam"), "image")
|
||||
iface = gr.Interface(snap, gr.inputs.Image(shape=(100,100), image_mode="L", source="webcam"), "image")
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -16,7 +16,8 @@ def zip_to_json(file_obj):
|
||||
return files
|
||||
|
||||
|
||||
io = gr.Interface(zip_to_json, "file", "json")
|
||||
iface = gr.Interface(zip_to_json, "file", "json")
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -11,7 +11,7 @@ def zip_two_files(file1, file2):
|
||||
return "tmp.zip"
|
||||
|
||||
|
||||
io = gr.Interface(
|
||||
iface = gr.Interface(
|
||||
zip_two_files,
|
||||
["file", "file"],
|
||||
"file",
|
||||
@ -21,5 +21,6 @@ io = gr.Interface(
|
||||
]
|
||||
)
|
||||
|
||||
io.test_launch()
|
||||
io.launch()
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
Loading…
Reference in New Issue
Block a user