Skip to content

Commit cc0cff8

Browse files
committed
Format The Codebase
- black formatting - isort formatting
1 parent 7fc0c83 commit cc0cff8

File tree

82 files changed

+12627
-2611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+12627
-2611
lines changed

demo/calculator/run.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gradio as gr
22

3+
34
def calculator(num1, operation, num2):
45
if operation == "add":
56
return num1 + num2
@@ -10,7 +11,9 @@ def calculator(num1, operation, num2):
1011
elif operation == "divide":
1112
return num1 / num2
1213

13-
iface = gr.Interface(calculator,
14+
15+
iface = gr.Interface(
16+
calculator,
1417
["number", gr.inputs.Radio(["add", "subtract", "multiply", "divide"]), "number"],
1518
"number",
1619
examples=[

demo/calculator_live/run.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gradio as gr
22

3+
34
def calculator(num1, operation, num2):
45
if operation == "add":
56
return num1 + num2
@@ -10,10 +11,12 @@ def calculator(num1, operation, num2):
1011
elif operation == "divide":
1112
return num1 / num2
1213

13-
iface = gr.Interface(calculator,
14+
15+
iface = gr.Interface(
16+
calculator,
1417
["number", gr.inputs.Radio(["add", "subtract", "multiply", "divide"]), "number"],
1518
"number",
16-
live=True
19+
live=True,
1720
)
1821

1922
if __name__ == "__main__":

demo/chatbot/run.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import gradio as gr
21
import random
32

3+
import gradio as gr
4+
5+
46
def chat(message, history):
57
history = history or []
68
if message.startswith("How many"):
7-
response = random.randint(1,10)
9+
response = random.randint(1, 10)
810
elif message.startswith("How"):
911
response = random.choice(["Great", "Good", "Okay", "Bad"])
1012
elif message.startswith("Where"):
@@ -19,11 +21,19 @@ def chat(message, history):
1921
html += "</div>"
2022
return html, history
2123

22-
iface = gr.Interface(chat, ["text", "state"], ["html", "state"], css="""
24+
25+
iface = gr.Interface(
26+
chat,
27+
["text", "state"],
28+
["html", "state"],
29+
css="""
2330
.chatbox {display:flex;flex-direction:column}
2431
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
2532
.user_msg {background-color:cornflowerblue;color:white;align-self:start}
2633
.resp_msg {background-color:lightgray;align-self:self-end}
27-
""", allow_screenshot=False, allow_flagging="never")
34+
""",
35+
allow_screenshot=False,
36+
allow_flagging="never",
37+
)
2838
if __name__ == "__main__":
29-
iface.launch()
39+
iface.launch()

demo/diff_texts/run.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import gradio as gr
21
from difflib import Differ
32

3+
import gradio as gr
4+
5+
46
def diff_texts(text1, text2):
57
d = Differ()
68
return [
7-
(token[2:], token[0] if token[0] != " " else None) for token in d.compare(text1, text2)
9+
(token[2:], token[0] if token[0] != " " else None)
10+
for token in d.compare(text1, text2)
811
]
912

13+
1014
iface = gr.Interface(
1115
diff_texts,
1216
[
1317
gr.inputs.Textbox(
14-
lines=3, default="The quick brown fox jumped over the lazy dogs."),
15-
gr.inputs.Textbox(
16-
lines=3, default="The fast brown fox jumps over lazy dogs."),
18+
lines=3, default="The quick brown fox jumped over the lazy dogs."
19+
),
20+
gr.inputs.Textbox(lines=3, default="The fast brown fox jumps over lazy dogs."),
1721
],
18-
gr.outputs.HighlightedText())
22+
gr.outputs.HighlightedText(),
23+
)
1924
if __name__ == "__main__":
20-
iface.launch()
25+
iface.launch()

demo/digit_classifier/run.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import os
2+
from urllib.request import urlretrieve
3+
14
import tensorflow as tf
5+
26
import gradio
37
import gradio as gr
4-
from urllib.request import urlretrieve
5-
import os
68

7-
urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
9+
urlretrieve(
10+
"https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5"
11+
)
812
model = tf.keras.models.load_model("mnist-model.h5")
913

1014

@@ -13,11 +17,14 @@ def recognize_digit(image):
1317
prediction = model.predict(image).tolist()[0]
1418
return {str(i): prediction[i] for i in range(10)}
1519

16-
im = gradio.inputs.Image(shape=(28, 28), image_mode='L', invert_colors=False, source="canvas")
20+
21+
im = gradio.inputs.Image(
22+
shape=(28, 28), image_mode="L", invert_colors=False, source="canvas"
23+
)
1724

1825
iface = gr.Interface(
19-
recognize_digit,
20-
im,
26+
recognize_digit,
27+
im,
2128
gradio.outputs.Label(num_top_classes=3),
2229
live=True,
2330
interpretation="default",
@@ -28,4 +35,3 @@ def recognize_digit(image):
2835

2936
if __name__ == "__main__":
3037
iface.launch()
31-

demo/disease_report/run.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import gradio as gr
2-
import numpy as np
3-
from fpdf import FPDF
41
import os
52
import tempfile
63

4+
import numpy as np
5+
from fpdf import FPDF
6+
7+
import gradio as gr
8+
9+
710
def disease_report(img, scan_for, generate_report):
811
results = []
912
for i, mode in enumerate(["Red", "Green", "Blue"]):
@@ -16,28 +19,30 @@ def disease_report(img, scan_for, generate_report):
1619
pdf = FPDF()
1720
pdf.add_page()
1821
pdf.set_font("Arial", size=15)
19-
pdf.cell(200, 10, txt="Disease Report",
20-
ln=1, align='C')
21-
pdf.cell(200, 10, txt="A Gradio Demo.",
22-
ln=2, align='C')
22+
pdf.cell(200, 10, txt="Disease Report", ln=1, align="C")
23+
pdf.cell(200, 10, txt="A Gradio Demo.", ln=2, align="C")
2324
pdf.output(report)
2425
return results, report if generate_report else None
2526

26-
iface = gr.Interface(disease_report,
27+
28+
iface = gr.Interface(
29+
disease_report,
2730
[
28-
"image",
29-
gr.inputs.CheckboxGroup(["Cancer", "Rash", "Heart Failure", "Stroke", "Diabetes", "Pneumonia"]),
30-
"checkbox"
31+
"image",
32+
gr.inputs.CheckboxGroup(
33+
["Cancer", "Rash", "Heart Failure", "Stroke", "Diabetes", "Pneumonia"]
34+
),
35+
"checkbox",
3136
],
3237
[
3338
gr.outputs.Carousel(["text", "image"], label="Disease"),
34-
gr.outputs.File(label="Report")
39+
gr.outputs.File(label="Report"),
3540
],
3641
title="Disease Report",
3742
description="Upload an Xray and select the diseases to scan for.",
3843
theme="grass",
3944
flagging_options=["good", "bad", "etc"],
40-
allow_flagging="auto"
45+
allow_flagging="auto",
4146
)
4247

4348
if __name__ == "__main__":

demo/filter_records/run.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import gradio as gr
22

3+
34
def filter_records(records, gender):
4-
return records[records['gender'] == gender]
5+
return records[records["gender"] == gender]
6+
57

6-
iface = gr.Interface(filter_records,
7-
[
8-
gr.inputs.Dataframe(headers=["name", "age", "gender"], datatype=["str", "number", "str"], row_count=5),
9-
gr.inputs.Dropdown(["M", "F", "O"])
10-
],
11-
"dataframe",
12-
description="Enter gender as 'M', 'F', or 'O' for other."
8+
iface = gr.Interface(
9+
filter_records,
10+
[
11+
gr.inputs.Dataframe(
12+
headers=["name", "age", "gender"],
13+
datatype=["str", "number", "str"],
14+
row_count=5,
15+
),
16+
gr.inputs.Dropdown(["M", "F", "O"]),
17+
],
18+
"dataframe",
19+
description="Enter gender as 'M', 'F', or 'O' for other.",
1320
)
1421

1522
iface.test_launch()
1623

1724
if __name__ == "__main__":
1825
iface.launch()
19-

demo/form_graph/run.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import gradio as gr
21
import random
2+
33
import matplotlib.pyplot as plt
44
import numpy as np
55

6+
import gradio as gr
7+
68

79
def plot_forecast(final_year, companies, noise, show_legend, point_style):
810
start_year = 2020
@@ -22,18 +24,19 @@ def plot_forecast(final_year, companies, noise, show_legend, point_style):
2224
return fig
2325

2426

25-
iface = gr.Interface(plot_forecast,
26-
[
27-
gr.inputs.Radio([2025, 2030, 2035, 2040],
28-
label="Project to:"),
29-
gr.inputs.CheckboxGroup(
30-
["Google", "Microsoft", "Gradio"], label="Company Selection"),
31-
gr.inputs.Slider(1, 100, label="Noise Level"),
32-
gr.inputs.Checkbox(label="Show Legend"),
33-
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
34-
],
35-
gr.outputs.Image(plot=True, label="forecast")
36-
)
27+
iface = gr.Interface(
28+
plot_forecast,
29+
[
30+
gr.inputs.Radio([2025, 2030, 2035, 2040], label="Project to:"),
31+
gr.inputs.CheckboxGroup(
32+
["Google", "Microsoft", "Gradio"], label="Company Selection"
33+
),
34+
gr.inputs.Slider(1, 100, label="Noise Level"),
35+
gr.inputs.Checkbox(label="Show Legend"),
36+
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
37+
],
38+
gr.outputs.Image(plot=True, label="forecast"),
39+
)
3740

3841
if __name__ == "__main__":
3942
iface.launch()

demo/fraud_detector/run.py

+27-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
import gradio as gr
2-
import pandas as pd
31
import random
42

3+
import pandas as pd
4+
5+
import gradio as gr
6+
57

68
def fraud_detector(card_activity, categories, sensitivity):
79
activity_range = random.randint(0, 100)
8-
drop_columns = [column for column in ["retail", "food", "other"] if column not in categories]
10+
drop_columns = [
11+
column for column in ["retail", "food", "other"] if column not in categories
12+
]
913
if len(drop_columns):
1014
card_activity.drop(columns=drop_columns, inplace=True)
11-
return card_activity, card_activity, {"fraud": activity_range / 100., "not fraud": 1 - activity_range / 100.}
15+
return (
16+
card_activity,
17+
card_activity,
18+
{"fraud": activity_range / 100.0, "not fraud": 1 - activity_range / 100.0},
19+
)
1220

1321

14-
iface = gr.Interface(fraud_detector,
15-
[
16-
gr.inputs.Timeseries(
17-
x="time",
18-
y=["retail", "food", "other"]
19-
),
20-
gr.inputs.CheckboxGroup(["retail", "food", "other"], default=[
21-
"retail", "food", "other"]),
22-
gr.inputs.Slider(1, 3)
23-
],
24-
[
25-
"dataframe",
26-
gr.outputs.Timeseries(
27-
x="time",
28-
y=["retail", "food", "other"]
29-
),
30-
gr.outputs.Label(label="Fraud Level"),
31-
]
32-
)
22+
iface = gr.Interface(
23+
fraud_detector,
24+
[
25+
gr.inputs.Timeseries(x="time", y=["retail", "food", "other"]),
26+
gr.inputs.CheckboxGroup(
27+
["retail", "food", "other"], default=["retail", "food", "other"]
28+
),
29+
gr.inputs.Slider(1, 3),
30+
],
31+
[
32+
"dataframe",
33+
gr.outputs.Timeseries(x="time", y=["retail", "food", "other"]),
34+
gr.outputs.Label(label="Fraud Level"),
35+
],
36+
)
3337
if __name__ == "__main__":
3438
iface.launch()

0 commit comments

Comments
 (0)