add client wheel (#7612)

This commit is contained in:
Ali Abdalla 2024-03-05 11:00:18 -08:00 committed by GitHub
parent 9c6de6d850
commit 82263ed365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -117,6 +117,7 @@ jobs:
run: |
python scripts/upload_website_demos.py --AUTH_TOKEN ${{ secrets.WEBSITE_SPACES_DEPLOY_TOKEN }} \
--WHEEL_URL https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/ \
--CLIENT_URL "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python" \
--GRADIO_VERSION ${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}
- name: log
run: |

View File

@ -27,7 +27,8 @@ def upload_demo_to_space(
space_id: str,
hf_token: str,
gradio_version: str | None,
gradio_wheel_url: str | None = None
gradio_wheel_url: str | None = None,
gradio_client_url: str | None = None
):
"""Upload a demo in the demo directory to a huggingface space.
Parameters:
@ -36,6 +37,7 @@ def upload_demo_to_space(
hf_token: HF api token. Need to have permission to write to space_id for this to work.
gradio_version: If not None, will set the gradio version in the created Space to the given version.
gradio_wheel_url: If not None, will install the version of gradio using the wheel url in the created Space.
gradio_client_url: If not None, will install the version of gradio client using the wheel url in the created Space.
"""
with tempfile.TemporaryDirectory() as tmpdir:
@ -57,17 +59,17 @@ def upload_demo_to_space(
"""
readme.open("w").write(textwrap.dedent(readme_content))
if gradio_wheel_url:
if gradio_wheel_url and gradio_client_url:
requirements_path = os.path.join(tmpdir, "requirements.txt")
if not os.path.exists(requirements_path):
with open(os.path.join(requirements_path), "w") as f:
f.write(gradio_wheel_url)
f.write(gradio_client_url + "\n" + gradio_wheel_url)
else:
with open(os.path.join(requirements_path), "r") as f:
content = f.read()
with open(os.path.join(requirements_path), "w") as f:
f.seek(0, 0)
f.write(gradio_wheel_url + '\n' + content)
f.write(gradio_client_url + "\n" + gradio_wheel_url + "\n" + content)
api = huggingface_hub.HfApi()
huggingface_hub.create_repo(
@ -93,13 +95,15 @@ demos = [demo for demo in demos if demo not in DEMOS_TO_SKIP and os.path.isdir(o
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--WHEEL_URL", type=str, help="aws link to gradio wheel")
parser.add_argument("--CLIENT_URL", type=str, help="gradio version")
parser.add_argument("--AUTH_TOKEN", type=str, help="huggingface auth token")
parser.add_argument("--GRADIO_VERSION", type=str, help="gradio version")
args = parser.parse_args()
gradio_wheel_url = args.WHEEL_URL + f"gradio-{args.GRADIO_VERSION}-py3-none-any.whl"
if args.AUTH_TOKEN is not None:
hello_world_version = str(huggingface_hub.space_info("gradio/hello_world").cardData["sdk_version"])
for demo in demos:
if hello_world_version != args.GRADIO_VERSION:
upload_demo_to_space(demo_name=demo, space_id="gradio/" + demo, hf_token=args.AUTH_TOKEN, gradio_version=args.GRADIO_VERSION)
upload_demo_to_space(demo_name=demo, space_id="gradio/" + demo + "_main", hf_token=args.AUTH_TOKEN, gradio_version=args.GRADIO_VERSION, gradio_wheel_url=gradio_wheel_url)
upload_demo_to_space(demo_name=demo, space_id="gradio/" + demo + "_main", hf_token=args.AUTH_TOKEN, gradio_version=args.GRADIO_VERSION, gradio_wheel_url=gradio_wheel_url, gradio_client_url=args.CLIENT_URL)