Skip to content

Commit 9492d5a

Browse files
author
Ali Abid
committed
Merge branch 'blocks-dev'
2 parents 13a1034 + 3dfc726 commit 9492d5a

517 files changed

Lines changed: 33074 additions & 7626 deletions

File tree

Some content is hidden

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

.circleci/config.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2.1
22
orbs:
3-
codecov: codecov/codecov@3.1.1
3+
codecov: codecov/codecov@3.2.2
44
node: circleci/node@4.7.0
55
jobs:
66
build:
@@ -11,6 +11,11 @@ jobs:
1111
- run: mkdir test-reports
1212
- restore_cache:
1313
key: deps1-{{ .Branch }}-{{ checksum "gradio.egg-info/requires.txt" }}
14+
- run:
15+
name: Install ffmpeg
16+
command: |
17+
sudo apt update
18+
sudo apt install ffmpeg -y
1419
- run:
1520
name: Install Python deps in a venv
1621
command: |
@@ -38,11 +43,6 @@ jobs:
3843
- run:
3944
command: |
4045
mkdir screenshots
41-
- run:
42-
command: |
43-
. venv/bin/activate
44-
coverage run -m pytest
45-
coverage xml
4646
- run:
4747
command: |
4848
. venv/bin/activate
@@ -55,6 +55,11 @@ jobs:
5555
command: |
5656
. venv/bin/activate
5757
python -m flake8 --ignore=E731,E501,E722,W503,E126,F401,E203 gradio test
58+
- run:
59+
command: |
60+
. venv/bin/activate
61+
coverage run -m pytest
62+
coverage xml
5863
- codecov/upload:
5964
file: 'coverage.xml'
6065
- store_artifacts:

.github/workflows/ui.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: gradio-ui
22

33
on:
44
push:
5-
branches:
6-
- "master"
5+
branches:
6+
- "main"
77
paths:
88
- "ui/**"
99
pull_request:
@@ -12,23 +12,31 @@ on:
1212

1313
defaults:
1414
run:
15-
working-directory: ./ui
15+
working-directory: ui
16+
17+
env:
18+
CI: true
19+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
20+
NODE_OPTIONS: "--max-old-space-size=4096"
1621

1722
concurrency:
1823
group: deploy-${{ github.ref }}-${{ github.event_name == 'push' || github.event.inputs.fire != null }}
1924
cancel-in-progress: true
2025

2126
jobs:
22-
check:
27+
quick-checks:
2328
name: static checks
2429
runs-on: ubuntu-latest
2530
steps:
26-
- uses: actions/checkout@v2
27-
- run: npm i -g pnpm@6
28-
- uses: actions/setup-node@v2
31+
- uses: actions/checkout@v3
32+
- uses: pnpm/action-setup@v2.2.1
33+
with:
34+
version: 6
35+
- uses: actions/setup-node@v3
2936
with:
3037
node-version: 16
31-
38+
cache: pnpm
39+
cache-dependency-path: ui/pnpm-lock.yaml
3240
- name: install dependencies
3341
run: pnpm i --frozen-lockfile
3442
- name: formatting check
@@ -38,5 +46,32 @@ jobs:
3846
continue-on-error: true
3947
- name: unit tests
4048
run: pnpm test:run
41-
- name: build
42-
run: pnpm build
49+
functional-test:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v3
53+
- uses: pnpm/action-setup@v2.2.1
54+
with:
55+
version: 6
56+
- uses: actions/setup-node@v3
57+
with:
58+
node-version: 16
59+
cache: pnpm
60+
cache-dependency-path: ui/pnpm-lock.yaml
61+
- name: Cache browsers
62+
id: browser_cache
63+
uses: actions/cache@main
64+
with:
65+
path: "~/.cache/ms-playwright"
66+
key: chromium-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
67+
- run: pnpm install --frozen-lockfile
68+
- run: pnpx playwright install chromium
69+
- run: pnpm build
70+
- run: pnpm test:browser
71+
- name: Upload failed tests screenshots
72+
if: failure()
73+
uses: actions/upload-artifact@v3
74+
with:
75+
retention-days: 3
76+
name: test-failure-${{ github.run_id }}
77+
path: ui/packages/app/test-results

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.formatting.provider": "black"
3+
}

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ coverage:
88
source:
99
paths:
1010
- "gradio/"
11-
target: 80%
11+
target: 70%
1212
threshold: 0.1
1313
patch: off
1414

demo/blocks_flashcards/run.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import random
2+
3+
import gradio as gr
4+
5+
demo = gr.Blocks()
6+
7+
with demo:
8+
gr.Markdown(
9+
"Load the flashcards in the table below, then use the Practice tab to practice."
10+
)
11+
12+
with gr.Tabs():
13+
with gr.TabItem("Word Bank"):
14+
flashcards_table = gr.Dataframe(headers=["front", "back"], type="array")
15+
with gr.TabItem("Practice"):
16+
with gr.Row():
17+
front = gr.Textbox()
18+
answer_row = gr.Row(visible=False)
19+
with answer_row:
20+
back = gr.Textbox()
21+
with gr.Row():
22+
new_btn = gr.Button("New Card")
23+
flip_btn = gr.Button("Flip Card")
24+
selected_card = gr.Variable()
25+
feedback_row = gr.Row(visible=False)
26+
with feedback_row:
27+
correct_btn = gr.Button(
28+
"Correct",
29+
css={"background-color": "lightgreen", "color": "green"},
30+
)
31+
incorrect_btn = gr.Button(
32+
"Incorrect", css={"background-color": "pink", "color": "red"}
33+
)
34+
with gr.TabItem("Results"):
35+
results = gr.Variable(default_value={})
36+
correct_field = gr.Markdown("# Correct: 0")
37+
incorrect_field = gr.Markdown("# Incorrect: 0")
38+
gr.Markdown("Card Statistics: ")
39+
results_table = gr.Dataframe(headers=["Card", "Correct", "Incorrect"])
40+
41+
def load_new_card(flashcards):
42+
card = random.choice(flashcards)
43+
return card, card[0], False, False
44+
45+
new_btn.click(
46+
load_new_card,
47+
[flashcards_table],
48+
[selected_card, front, answer_row, feedback_row],
49+
)
50+
51+
def flip_card(card):
52+
return card[1], True, True
53+
54+
flip_btn.click(flip_card, [selected_card], [back, answer_row, feedback_row])
55+
56+
def mark_correct(card, results):
57+
if card[0] not in results:
58+
results[card[0]] = [0, 0]
59+
results[card[0]][0] += 1
60+
correct_count = sum(result[0] for result in results.values())
61+
return (
62+
results,
63+
f"# Correct: {correct_count}",
64+
[[front, scores[0], scores[1]] for front, scores in results.items()],
65+
)
66+
67+
def mark_incorrect(card, results):
68+
if card[0] not in results:
69+
results[card[0]] = [0, 0]
70+
results[card[0]][1] += 1
71+
incorrect_count = sum(result[1] for result in results.values())
72+
return (
73+
results,
74+
f"# Inorrect: {incorrect_count}",
75+
[[front, scores[0], scores[1]] for front, scores in results.items()],
76+
)
77+
78+
correct_btn.click(
79+
mark_correct,
80+
[selected_card, results],
81+
[results, correct_field, results_table],
82+
)
83+
84+
incorrect_btn.click(
85+
mark_incorrect,
86+
[selected_card, results],
87+
[results, incorrect_field, results_table],
88+
)
89+
90+
if __name__ == "__main__":
91+
demo.launch()

demo/blocks_inputs/run.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import gradio as gr
2+
3+
str = """Hello friends
4+
hello friends
5+
6+
Hello friends
7+
8+
"""
9+
10+
11+
with gr.Blocks() as demo:
12+
txt = gr.Textbox(label="Input", lines=5)
13+
txt_2 = gr.Textbox(label="Output")
14+
txt_3 = gr.Textbox(str, label="Output")
15+
btn = gr.Button("Submit")
16+
btn.click(lambda a: a, inputs=[txt], outputs=[txt_2])
17+
18+
if __name__ == "__main__":
19+
demo.launch()

demo/blocks_kinematics/run.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
import gradio as gr
5+
6+
7+
def plot(v, a):
8+
g = 9.81
9+
theta = a / 180 * 3.14
10+
tmax = ((2 * v) * np.sin(theta)) / g
11+
timemat = tmax * np.linspace(0, 1, 40)[:, None]
12+
13+
x = (v * timemat) * np.cos(theta)
14+
y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
15+
16+
fig = plt.figure()
17+
plt.scatter(x=x, y=y, marker=".")
18+
plt.xlim(0, 100)
19+
plt.ylim(0, 60)
20+
return fig
21+
22+
23+
demo = gr.Blocks()
24+
25+
with demo:
26+
gr.Markdown(
27+
"Let's do some kinematics! Choose the speed and angle to see the trajectory."
28+
)
29+
30+
with gr.Row():
31+
speed = gr.Slider(25, min=1, max=30, label="Speed")
32+
angle = gr.Slider(45, min=0, max=90, label="Angle")
33+
output = gr.Image(type="plot")
34+
btn = gr.Button("Run")
35+
btn.click(plot, [speed, angle], output)
36+
37+
if __name__ == "__main__":
38+
demo.launch()
92.9 KB
Binary file not shown.
150 KB
Binary file not shown.
375 KB
Binary file not shown.

0 commit comments

Comments
 (0)