Skip to content

Commit

Permalink
merge main (#9050)
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton authored Aug 7, 2024
1 parent 382a561 commit 7ad19b2
Show file tree
Hide file tree
Showing 33 changed files with 414 additions and 150 deletions.
6 changes: 6 additions & 0 deletions .changeset/cuddly-loops-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gradio": patch
"gradio_client": patch
---

feat:Improvements to FRP client download and usage
5 changes: 5 additions & 0 deletions .changeset/ten-lands-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

feat:Some tweaks to is_in_or_equal
9 changes: 3 additions & 6 deletions .github/workflows/previews-build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: "previews-build"

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- 5.0-dev

env:
CI: true
Expand Down Expand Up @@ -35,7 +32,7 @@ jobs:
name: "previews-build"
runs-on: ubuntu-22.04
needs: changes
if: needs.changes.outputs.should_run == 'true'
if: needs.changes.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- name: install dependencies
Expand Down Expand Up @@ -72,7 +69,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: all_demos
path: demo/all_demos
path: demo
- name: Create JS client tarball
id: create_js_tarball
continue-on-error: true
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/previews-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: "previews-deploy"

on:
workflow_dispatch:
workflow_run:
workflows: ["previews-build"]
types:
Expand All @@ -15,6 +14,7 @@ jobs:
changes:
name: "changes"
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
permissions:
actions: read
outputs:
Expand All @@ -41,7 +41,7 @@ jobs:
comment-spaces-start:
needs: changes
uses: "./.github/workflows/comment-queue.yml"
if: ${{ needs.changes.outputs.should_run == 'true' }}
if: ${{github.event.workflow_run.conclusion == 'success' && needs.changes.outputs.should_run == 'true' }}
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
Expand All @@ -54,7 +54,7 @@ jobs:
space_url: ${{ steps.upload-demo.outputs.SPACE_URL }}
js_tarball_url: ${{ steps.upload_js_tarball.outputs.js_tarball_url }}
needs: changes
if: ${{ needs.changes.outputs.should_run == 'true' }}
if: ${{ (github.event.workflow_run.conclusion == 'success' && needs.changes.outputs.should_run == 'true') || github.event.workflow_run.event == 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
actions: read
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
curl https://raw.githubusercontent.com/gradio-app/gradio/main/scripts/upload_demo_to_space.py -o scripts/upload_demo_to_space.py
curl https://raw.githubusercontent.com/gradio-app/gradio/main/scripts/upload_website_demos.py -o scripts/upload_website_demos.py
- name: make dirs
run: mkdir -p demo/all_demos && mv all_demos/* demo/all_demos/
run: mkdir -p demo && mv all_demos/* demo/
- name: Upload demo to spaces
if: github.event.workflow_run.event == 'pull_request'
id: upload-demo
Expand All @@ -115,7 +115,7 @@ jobs:
--gradio-version ${{ needs.changes.outputs.gradio_version }} > url.txt
echo "SPACE_URL=$(cat url.txt)" >> $GITHUB_OUTPUT
- name: Upload Website Demos
if: github.event_name == 'workflow_dispatch'
if: github.event.workflow_run.event == 'workflow_dispatch'
id: upload-website-demos
run: |
python scripts/upload_website_demos.py --AUTH_TOKEN ${{ secrets.WEBSITE_SPACES_DEPLOY_TOKEN }} \
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
comment-spaces-failure:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy, changes]
if: always() && needs.deploy.result == 'failure' && needs.changes.outputs.should_run == 'true'
if: always() && github.event.workflow_run.conclusion == 'success' && needs.deploy.result == 'failure' && needs.changes.outputs.should_run == 'true'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ jobs:
- name: trigger spaces deploy workflow
env:
GITHUB_TOKEN: ${{ secrets.COMMENT_TOKEN }}
run: gh workflow run deploy-spaces.yml
run: gh workflow run previews-build.yml
9 changes: 5 additions & 4 deletions .github/workflows/storybook-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
changes:
name: "changes"
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
permissions:
actions: read
outputs:
Expand Down Expand Up @@ -48,7 +49,7 @@ jobs:
update-status:
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.should_run == 'false' || contains(needs.changes.outputs.labels, 'no-visual-update') }}
if: ${{ github.event.workflow_run.conclusion == 'success' && (needs.changes.outputs.should_run == 'false' || contains(needs.changes.outputs.labels, 'no-visual-update')) }}
steps:
- name: update status
uses: gradio-app/github/actions/set-commit-status@main
Expand All @@ -61,7 +62,7 @@ jobs:
environment: storybook
name: "storybook-deploy"
needs: changes
if: ${{ needs.changes.outputs.should_run == 'true' && github.repository == 'gradio-app/gradio' && !contains(needs.changes.outputs.labels, 'no-visual-update') }}
if: ${{ github.event.workflow_run.conclusion == 'success' && needs.changes.outputs.should_run == 'true' && github.repository == 'gradio-app/gradio' && !contains(needs.changes.outputs.labels, 'no-visual-update') }}
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.publish-chromatic.outputs.changeCount }}
Expand Down Expand Up @@ -103,14 +104,14 @@ jobs:
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.changes.outputs.pr_number }}
pr_number: ${{ github.event.workflow_run.conclusion == 'success' && needs.changes.outputs.pr_number }}
message: |
storybook~success~${{ needs.deploy.outputs.storybook_url }}
comment-chromatic-fail:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy, changes]
if: always() && needs.deploy.result == 'failure'
if: always() && github.event.workflow_run.conclusion == 'success' && needs.deploy.result == 'failure'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/test-functional-lite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "functional-lite"

on:
pull_request:
push:
branches:
- main
- 5.0-dev

concurrency:
group: "${{ github.event.pull_request.number }}-${{ github.ref_name }}-${{ github.workflow }}"
cancel-in-progress: true

jobs:
changes:
name: "changes"
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.changes.outputs.should_run }}
sha: ${{ steps.changes.outputs.sha }}
pr_number: ${{ steps.changes.outputs.pr_number }}
source_branch: ${{ steps.changes.outputs.source_branch }}
source_repo: ${{ steps.changes.outputs.source_repo }}
steps:
- uses: actions/checkout@v4
- uses: "gradio-app/gradio/.github/actions/changes@main"
id: changes
with:
filter: "functional"
token: ${{ secrets.GITHUB_TOKEN }}
test:
name: "functional-test-lite"
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- name: install dependencies
id: install_deps
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
always_install_pnpm: true
build_lite: true
skip_build: true
- run: pnpm exec playwright install chromium firefox
- name: Run Lite E2E tests
run: |
. venv/bin/activate
pnpm --filter @gradio/app test:browser:lite
- name: Get the performance result
run: |
export LITE_APP_LOAD_TIME=$(jq -r '.app_load_time' .lite-perf.json)
echo "LITE_APP_LOAD_TIME=$LITE_APP_LOAD_TIME" >> $GITHUB_ENV
cat .lite-perf.json # For debugging
11 changes: 1 addition & 10 deletions .github/workflows/test-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
always_install_pnpm: true
build_lite: true
- name: install demo dependencies
- name: install outbreak_forecast dependencies
run: |
. venv/bin/activate
python -m pip install -r demo/outbreak_forecast/requirements.txt
Expand Down Expand Up @@ -74,12 +74,3 @@ jobs:
name: reload-mode-playwright-screenshots
path: |
./test-results
- name: Run Lite E2E tests
run: |
. venv/bin/activate
pnpm --filter @gradio/app test:browser:lite
- name: Get the performance result
run: |
export LITE_APP_LOAD_TIME=$(jq -r '.app_load_time' .lite-perf.json)
echo "LITE_APP_LOAD_TIME=$LITE_APP_LOAD_TIME" >> $GITHUB_ENV
cat .lite-perf.json # For debugging
5 changes: 4 additions & 1 deletion .github/workflows/update-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "update-checks"

on:
workflow_run:
workflows: ["python", "js", "functional"]
workflows: ["python", "js", "functional", "functional-lite"]
types:
- completed

Expand Down Expand Up @@ -50,6 +50,9 @@ jobs:
- name: set functional check name
if: github.event.workflow_run.name == 'functional'
run: echo "CHECK_NAME=functional / functional-test (pull_request)" >> $GITHUB_ENV
- name: set functional-lite check name
if: github.event.workflow_run.name == 'functional-lite'
run: echo "CHECK_NAME=functional-lite / functional-test-lite (pull_request)" >> $GITHUB_ENV
- name: update status
uses: gradio-app/github/actions/set-commit-status@main
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/website-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ jobs:
name: "website-build"
runs-on: ubuntu-22.04
needs: changes
if: needs.changes.outputs.should_run == 'true'
if: needs.changes.outputs.should_run == 'true' || (github.ref_name == 'main' && github.repository == 'gradio-app/gradio')
steps:
- uses: actions/checkout@v4
- name: install dependencies
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
always_install_pnpm: true
skip_build: true
# unsafe - pr could have modified the build script
- name: build client
run: pnpm --filter @gradio/client build

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/website-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
comment-deploy-start:
needs: changes
uses: "./.github/workflows/comment-queue.yml"
if: github.event.workflow_run.conclusion == 'success' && needs.changes.outputs.should_run == 'true'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
Expand All @@ -48,7 +49,7 @@ jobs:
name: "website-deploy"
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.should_run == 'true'
if: github.event.workflow_run.conclusion == 'success' && (needs.changes.outputs.should_run == 'true' || github.event.workflow_run.event == 'push')
permissions:
actions: read
outputs:
Expand Down Expand Up @@ -115,7 +116,7 @@ jobs:
comment-deploy-success:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy, changes]
if: needs.deploy.result == 'success' && needs.changes.outputs.pr_number != 'false'
if: github.event.workflow_run.conclusion == 'success' && needs.deploy.result == 'success' && needs.changes.outputs.pr_number != 'false'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
Expand All @@ -124,7 +125,7 @@ jobs:
comment-deploy-failure:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy, changes]
if: always() && needs.deploy.result == 'failure' && needs.changes.outputs.pr_number != 'false'
if: always() && github.event.workflow_run.conclusion == 'success' && needs.deploy.result == 'failure' && needs.changes.outputs.pr_number != 'false'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ coverage.xml
test.txt
**/snapshots/**/*.png
playwright-report/
.hypothesis

# Demos
demo/tmp.zip
Expand Down
8 changes: 4 additions & 4 deletions client/python/gradio_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ def _download_file(self, x: dict) -> str:
if self.client.output_dir is not None:
os.makedirs(self.client.output_dir, exist_ok=True)

sha1 = hashlib.sha1()
sha = hashlib.sha256()
temp_dir = Path(tempfile.gettempdir()) / secrets.token_hex(20)
temp_dir.mkdir(exist_ok=True, parents=True)

Expand All @@ -1380,11 +1380,11 @@ def _download_file(self, x: dict) -> str:
) as response:
response.raise_for_status()
with open(temp_dir / Path(url_path).name, "wb") as f:
for chunk in response.iter_bytes(chunk_size=128 * sha1.block_size):
sha1.update(chunk)
for chunk in response.iter_bytes(chunk_size=128 * sha.block_size):
sha.update(chunk)
f.write(chunk)

directory = Path(self.client.output_dir) / sha1.hexdigest()
directory = Path(self.client.output_dir) / sha.hexdigest()
directory.mkdir(exist_ok=True, parents=True)
dest = directory / Path(url_path).name
shutil.move(temp_dir / Path(url_path).name, dest)
Expand Down
2 changes: 1 addition & 1 deletion demo/gif_maker/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: gif_maker"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio opencv-python"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import cv2\n", "import gradio as gr\n", "\n", "def gif_maker(img_files):\n", " img_array = []\n", " size = (1, 1)\n", " for filename in img_files:\n", " img = cv2.imread(filename.name)\n", " height, width, _ = img.shape\n", " size = (width,height)\n", " img_array.append(img)\n", " output_file = \"test.mp4\"\n", " out = cv2.VideoWriter(output_file,cv2.VideoWriter_fourcc(*'h264'), 15, size)\n", " for i in range(len(img_array)):\n", " out.write(img_array[i])\n", " out.release()\n", " return output_file\n", "\n", "demo = gr.Interface(gif_maker, inputs=gr.File(file_count=\"multiple\"), outputs=gr.Video())\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: gif_maker"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio opencv-python"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import cv2\n", "import gradio as gr\n", "\n", "def gif_maker(img_files):\n", " img_array = []\n", " size = (1, 1)\n", " for filename in img_files:\n", " img = cv2.imread(filename.name)\n", " height, width, _ = img.shape\n", " size = (width,height)\n", " img_array.append(img)\n", " output_file = \"test.mp4\"\n", " out = cv2.VideoWriter(output_file,cv2.VideoWriter_fourcc(*'h264'), 15, size) # type: ignore\n", " for i in range(len(img_array)):\n", " out.write(img_array[i])\n", " out.release()\n", " return output_file\n", "\n", "demo = gr.Interface(gif_maker, inputs=gr.File(file_count=\"multiple\"), outputs=gr.Video())\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
2 changes: 1 addition & 1 deletion demo/gif_maker/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def gif_maker(img_files):
size = (width,height)
img_array.append(img)
output_file = "test.mp4"
out = cv2.VideoWriter(output_file,cv2.VideoWriter_fourcc(*'h264'), 15, size)
out = cv2.VideoWriter(output_file,cv2.VideoWriter_fourcc(*'h264'), 15, size) # type: ignore
for i in range(len(img_array)):
out.write(img_array[i])
out.release()
Expand Down
2 changes: 1 addition & 1 deletion demo/white_noise_vid_not_playable/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: white_noise_vid_not_playable"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio opencv-python"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import cv2\n", "import gradio as gr\n", "import numpy as np\n", "\n", "def gif_maker():\n", " img_array = []\n", " height, width = 50, 50\n", " for i in range(30):\n", " img_array.append(np.random.randint(0, 255, size=(height, width, 3)).astype(np.uint8))\n", " output_file = \"test.mp4\"\n", " out = cv2.VideoWriter(output_file, cv2.VideoWriter_fourcc(*'mp4v'), 15, (height, width))\n", " for i in range(len(img_array)):\n", " out.write(img_array[i])\n", " out.release()\n", " return output_file, output_file\n", "\n", "demo = gr.Interface(gif_maker, inputs=None, outputs=[gr.Video(), gr.File()])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: white_noise_vid_not_playable"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio opencv-python"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import cv2\n", "import gradio as gr\n", "import numpy as np\n", "\n", "def gif_maker():\n", " img_array = []\n", " height, width = 50, 50\n", " for i in range(30):\n", " img_array.append(np.random.randint(0, 255, size=(height, width, 3)).astype(np.uint8))\n", " output_file = \"test.mp4\"\n", " out = cv2.VideoWriter(output_file, cv2.VideoWriter_fourcc(*'mp4v'), 15, (height, width)) # type: ignore\n", " for i in range(len(img_array)):\n", " out.write(img_array[i])\n", " out.release()\n", " return output_file, output_file\n", "\n", "demo = gr.Interface(gif_maker, inputs=None, outputs=[gr.Video(), gr.File()])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
2 changes: 1 addition & 1 deletion demo/white_noise_vid_not_playable/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def gif_maker():
for i in range(30):
img_array.append(np.random.randint(0, 255, size=(height, width, 3)).astype(np.uint8))
output_file = "test.mp4"
out = cv2.VideoWriter(output_file, cv2.VideoWriter_fourcc(*'mp4v'), 15, (height, width))
out = cv2.VideoWriter(output_file, cv2.VideoWriter_fourcc(*'mp4v'), 15, (height, width)) # type: ignore
for i in range(len(img_array)):
out.write(img_array[i])
out.release()
Expand Down
10 changes: 8 additions & 2 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
get_render_context,
set_render_context,
)
from gradio.data_classes import BlocksConfigDict, FileData, GradioModel, GradioRootModel
from gradio.data_classes import (
BlocksConfigDict,
DeveloperPath,
FileData,
GradioModel,
GradioRootModel,
)
from gradio.events import (
EventData,
EventListener,
Expand Down Expand Up @@ -410,7 +416,7 @@ def __init__(
render=render,
)

TEMPLATE_DIR = "./templates/"
TEMPLATE_DIR = DeveloperPath("./templates/")
FRONTEND_DIR = "../../frontend/"

@property
Expand Down
Loading

0 comments on commit 7ad19b2

Please sign in to comment.