Skip to content

Commit

Permalink
Format The Codebase
Browse files Browse the repository at this point in the history
- black formatting
- isort formatting
  • Loading branch information
omerXfaruq committed Jan 21, 2022
1 parent 7fc0c83 commit cc0cff8
Show file tree
Hide file tree
Showing 82 changed files with 12,627 additions and 2,611 deletions.
5 changes: 4 additions & 1 deletion demo/calculator/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gradio as gr


def calculator(num1, operation, num2):
if operation == "add":
return num1 + num2
Expand All @@ -10,7 +11,9 @@ def calculator(num1, operation, num2):
elif operation == "divide":
return num1 / num2

iface = gr.Interface(calculator,

iface = gr.Interface(
calculator,
["number", gr.inputs.Radio(["add", "subtract", "multiply", "divide"]), "number"],
"number",
examples=[
Expand Down
7 changes: 5 additions & 2 deletions demo/calculator_live/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gradio as gr


def calculator(num1, operation, num2):
if operation == "add":
return num1 + num2
Expand All @@ -10,10 +11,12 @@ def calculator(num1, operation, num2):
elif operation == "divide":
return num1 / num2

iface = gr.Interface(calculator,

iface = gr.Interface(
calculator,
["number", gr.inputs.Radio(["add", "subtract", "multiply", "divide"]), "number"],
"number",
live=True
live=True,
)

if __name__ == "__main__":
Expand Down
20 changes: 15 additions & 5 deletions demo/chatbot/run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import gradio as gr
import random

import gradio as gr


def chat(message, history):
history = history or []
if message.startswith("How many"):
response = random.randint(1,10)
response = random.randint(1, 10)
elif message.startswith("How"):
response = random.choice(["Great", "Good", "Okay", "Bad"])
elif message.startswith("Where"):
Expand All @@ -19,11 +21,19 @@ def chat(message, history):
html += "</div>"
return html, history

iface = gr.Interface(chat, ["text", "state"], ["html", "state"], css="""

iface = gr.Interface(
chat,
["text", "state"],
["html", "state"],
css="""
.chatbox {display:flex;flex-direction:column}
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
.user_msg {background-color:cornflowerblue;color:white;align-self:start}
.resp_msg {background-color:lightgray;align-self:self-end}
""", allow_screenshot=False, allow_flagging="never")
""",
allow_screenshot=False,
allow_flagging="never",
)
if __name__ == "__main__":
iface.launch()
iface.launch()
19 changes: 12 additions & 7 deletions demo/diff_texts/run.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import gradio as gr
from difflib import Differ

import gradio as gr


def diff_texts(text1, text2):
d = Differ()
return [
(token[2:], token[0] if token[0] != " " else None) for token in d.compare(text1, text2)
(token[2:], token[0] if token[0] != " " else None)
for token in d.compare(text1, text2)
]


iface = gr.Interface(
diff_texts,
[
gr.inputs.Textbox(
lines=3, default="The quick brown fox jumped over the lazy dogs."),
gr.inputs.Textbox(
lines=3, default="The fast brown fox jumps over lazy dogs."),
lines=3, default="The quick brown fox jumped over the lazy dogs."
),
gr.inputs.Textbox(lines=3, default="The fast brown fox jumps over lazy dogs."),
],
gr.outputs.HighlightedText())
gr.outputs.HighlightedText(),
)
if __name__ == "__main__":
iface.launch()
iface.launch()
20 changes: 13 additions & 7 deletions demo/digit_classifier/run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import os
from urllib.request import urlretrieve

import tensorflow as tf

import gradio
import gradio as gr
from urllib.request import urlretrieve
import os

urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
urlretrieve(
"https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5"
)
model = tf.keras.models.load_model("mnist-model.h5")


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

im = gradio.inputs.Image(shape=(28, 28), image_mode='L', invert_colors=False, source="canvas")

im = gradio.inputs.Image(
shape=(28, 28), image_mode="L", invert_colors=False, source="canvas"
)

iface = gr.Interface(
recognize_digit,
im,
recognize_digit,
im,
gradio.outputs.Label(num_top_classes=3),
live=True,
interpretation="default",
Expand All @@ -28,4 +35,3 @@ def recognize_digit(image):

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

31 changes: 18 additions & 13 deletions demo/disease_report/run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import gradio as gr
import numpy as np
from fpdf import FPDF
import os
import tempfile

import numpy as np
from fpdf import FPDF

import gradio as gr


def disease_report(img, scan_for, generate_report):
results = []
for i, mode in enumerate(["Red", "Green", "Blue"]):
Expand All @@ -16,28 +19,30 @@ def disease_report(img, scan_for, generate_report):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=15)
pdf.cell(200, 10, txt="Disease Report",
ln=1, align='C')
pdf.cell(200, 10, txt="A Gradio Demo.",
ln=2, align='C')
pdf.cell(200, 10, txt="Disease Report", ln=1, align="C")
pdf.cell(200, 10, txt="A Gradio Demo.", ln=2, align="C")
pdf.output(report)
return results, report if generate_report else None

iface = gr.Interface(disease_report,

iface = gr.Interface(
disease_report,
[
"image",
gr.inputs.CheckboxGroup(["Cancer", "Rash", "Heart Failure", "Stroke", "Diabetes", "Pneumonia"]),
"checkbox"
"image",
gr.inputs.CheckboxGroup(
["Cancer", "Rash", "Heart Failure", "Stroke", "Diabetes", "Pneumonia"]
),
"checkbox",
],
[
gr.outputs.Carousel(["text", "image"], label="Disease"),
gr.outputs.File(label="Report")
gr.outputs.File(label="Report"),
],
title="Disease Report",
description="Upload an Xray and select the diseases to scan for.",
theme="grass",
flagging_options=["good", "bad", "etc"],
allow_flagging="auto"
allow_flagging="auto",
)

if __name__ == "__main__":
Expand Down
24 changes: 15 additions & 9 deletions demo/filter_records/run.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import gradio as gr


def filter_records(records, gender):
return records[records['gender'] == gender]
return records[records["gender"] == gender]


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"])
],
"dataframe",
description="Enter gender as 'M', 'F', or 'O' for other."
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"]),
],
"dataframe",
description="Enter gender as 'M', 'F', or 'O' for other.",
)

iface.test_launch()

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

29 changes: 16 additions & 13 deletions demo/form_graph/run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import gradio as gr
import random

import matplotlib.pyplot as plt
import numpy as np

import gradio as gr


def plot_forecast(final_year, companies, noise, show_legend, point_style):
start_year = 2020
Expand All @@ -22,18 +24,19 @@ def plot_forecast(final_year, companies, noise, show_legend, point_style):
return fig


iface = gr.Interface(plot_forecast,
[
gr.inputs.Radio([2025, 2030, 2035, 2040],
label="Project to:"),
gr.inputs.CheckboxGroup(
["Google", "Microsoft", "Gradio"], label="Company Selection"),
gr.inputs.Slider(1, 100, label="Noise Level"),
gr.inputs.Checkbox(label="Show Legend"),
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
],
gr.outputs.Image(plot=True, label="forecast")
)
iface = gr.Interface(
plot_forecast,
[
gr.inputs.Radio([2025, 2030, 2035, 2040], label="Project to:"),
gr.inputs.CheckboxGroup(
["Google", "Microsoft", "Gradio"], label="Company Selection"
),
gr.inputs.Slider(1, 100, label="Noise Level"),
gr.inputs.Checkbox(label="Show Legend"),
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
],
gr.outputs.Image(plot=True, label="forecast"),
)

if __name__ == "__main__":
iface.launch()
50 changes: 27 additions & 23 deletions demo/fraud_detector/run.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
import gradio as gr
import pandas as pd
import random

import pandas as pd

import gradio as gr


def fraud_detector(card_activity, categories, sensitivity):
activity_range = random.randint(0, 100)
drop_columns = [column for column in ["retail", "food", "other"] if column not in categories]
drop_columns = [
column for column in ["retail", "food", "other"] if column not in categories
]
if len(drop_columns):
card_activity.drop(columns=drop_columns, inplace=True)
return card_activity, card_activity, {"fraud": activity_range / 100., "not fraud": 1 - activity_range / 100.}
return (
card_activity,
card_activity,
{"fraud": activity_range / 100.0, "not fraud": 1 - activity_range / 100.0},
)


iface = gr.Interface(fraud_detector,
[
gr.inputs.Timeseries(
x="time",
y=["retail", "food", "other"]
),
gr.inputs.CheckboxGroup(["retail", "food", "other"], default=[
"retail", "food", "other"]),
gr.inputs.Slider(1, 3)
],
[
"dataframe",
gr.outputs.Timeseries(
x="time",
y=["retail", "food", "other"]
),
gr.outputs.Label(label="Fraud Level"),
]
)
iface = gr.Interface(
fraud_detector,
[
gr.inputs.Timeseries(x="time", y=["retail", "food", "other"]),
gr.inputs.CheckboxGroup(
["retail", "food", "other"], default=["retail", "food", "other"]
),
gr.inputs.Slider(1, 3),
],
[
"dataframe",
gr.outputs.Timeseries(x="time", y=["retail", "food", "other"]),
gr.outputs.Label(label="Fraud Level"),
],
)
if __name__ == "__main__":
iface.launch()
Loading

0 comments on commit cc0cff8

Please sign in to comment.