Fix typecheck error due to huggingface_hub update (#10460)

* fix typecheck

* add changeset

* fix test

* fix

* fix

* fix

* matplotlib

---------

Co-authored-by: Freddy Boulton <freddyboulton@hf-freddy.local>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Freddy Boulton 2025-01-29 14:29:36 -05:00 committed by GitHub
parent 7cc5aa195b
commit 324383fb81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 199 additions and 188 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
feat:Fix typecheck error due to huggingface_hub update

View File

@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: dataframe_streaming"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pandas as pd\n", "import time\n", "\n", "def update_dataframe(df):\n", " df.iloc[:, :] = 1\n", " yield df, 1\n", " time.sleep(0.1)\n", " df.iloc[:, :] = 2\n", " yield df, 2\n", "\n", "def sum_values(df):\n", " return pd.to_numeric(df.values.flatten(), errors='coerce').sum()\n", "\n", "initial_df = pd.DataFrame(0, index=range(5), columns=range(5))\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " button = gr.Button(\"Update DataFrame\")\n", " number = gr.Number(value=0, label=\"Number\")\n", " dataframe = gr.Dataframe(value=initial_df, label=\"Dataframe\")\n", "\n", " button.click(fn=update_dataframe, inputs=dataframe, outputs=[dataframe, number])\n", " with gr.Row():\n", " change_events = gr.Number(label=\"Change events\")\n", " input_events = gr.Number(label=\"Input events\")\n", " sum_of_values = gr.Number(label=\"Sum of values\")\n", "\n", " dataframe.change(lambda x:x+1, inputs=change_events, outputs=change_events)\n", " dataframe.input(lambda x:x+1, inputs=input_events, outputs=input_events)\n", " dataframe.change(sum_values, inputs=dataframe, outputs=sum_of_values)\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: dataframe_streaming"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pandas as pd\n", "import time\n", "\n", "def update_dataframe(df):\n", " df.iloc[:, :] = 1\n", " yield df, 1\n", " time.sleep(0.1)\n", " df.iloc[:, :] = 2\n", " yield df, 2\n", "\n", "def sum_values(df):\n", " return pd.to_numeric(df.values.flatten(), errors='coerce').sum() # type: ignore\n", "\n", "initial_df = pd.DataFrame(0, index=range(5), columns=range(5))\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " button = gr.Button(\"Update DataFrame\")\n", " number = gr.Number(value=0, label=\"Number\")\n", " dataframe = gr.Dataframe(value=initial_df, label=\"Dataframe\")\n", "\n", " button.click(fn=update_dataframe, inputs=dataframe, outputs=[dataframe, number])\n", " with gr.Row():\n", " change_events = gr.Number(label=\"Change events\")\n", " input_events = gr.Number(label=\"Input events\")\n", " sum_of_values = gr.Number(label=\"Sum of values\")\n", "\n", " dataframe.change(lambda x:x+1, inputs=change_events, outputs=change_events)\n", " dataframe.input(lambda x:x+1, inputs=input_events, outputs=input_events)\n", " dataframe.change(sum_values, inputs=dataframe, outputs=sum_of_values)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}

View File

@ -10,7 +10,7 @@ def update_dataframe(df):
yield df, 2
def sum_values(df):
return pd.to_numeric(df.values.flatten(), errors='coerce').sum()
return pd.to_numeric(df.values.flatten(), errors='coerce').sum() # type: ignore
initial_df = pd.DataFrame(0, index=range(5), columns=range(5))

View File

@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: streaming_wav2vec"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio torch transformers "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from transformers import pipeline\n", "import gradio as gr\n", "import time\n", "\n", "p = pipeline(\"automatic-speech-recognition\")\n", "\n", "def transcribe(audio, state=\"\"):\n", " time.sleep(2)\n", " text = p(audio)[\"text\"] # type: ignore\n", " state += text + \" \"\n", " return state, state\n", "\n", "demo = gr.Interface(\n", " fn=transcribe,\n", " inputs=[\n", " gr.Audio(sources=[\"microphone\"], type=\"filepath\", streaming=True),\n", " \"state\"\n", " ],\n", " outputs=[\n", " \"textbox\",\n", " \"state\"\n", " ],\n", " live=True\n", ")\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: streaming_wav2vec"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio torch transformers "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from transformers import pipeline\n", "import gradio as gr\n", "import time\n", "\n", "p = pipeline(\"automatic-speech-recognition\")\n", "\n", "def transcribe(audio, state=\"\"):\n", " time.sleep(2)\n", " text = p(audio)[\"text\"] # type: ignore\n", " state += text + \" \" # type: ignore\n", " return state, state\n", "\n", "demo = gr.Interface(\n", " fn=transcribe,\n", " inputs=[\n", " gr.Audio(sources=[\"microphone\"], type=\"filepath\", streaming=True),\n", " \"state\"\n", " ],\n", " outputs=[\n", " \"textbox\",\n", " \"state\"\n", " ],\n", " live=True\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}

View File

@ -7,7 +7,7 @@ p = pipeline("automatic-speech-recognition")
def transcribe(audio, state=""):
time.sleep(2)
text = p(audio)["text"] # type: ignore
state += text + " "
state += text + " " # type: ignore
return state, state
demo = gr.Interface(

View File

@ -173,6 +173,8 @@ def from_model(
model_name: str, hf_token: str | Literal[False] | None, alias: str | None, **kwargs
) -> Blocks:
headers = {"X-Wait-For-Model": "true"}
if hf_token is False:
hf_token = None
client = huggingface_hub.InferenceClient(
model=model_name, headers=headers, token=hf_token
)
@ -430,7 +432,7 @@ def from_model(
data = preprocess(*data)
try:
data = fn(*data) # type: ignore
except huggingface_hub.utils.HfHubHTTPError as e:
except huggingface_hub.utils.HfHubHTTPError as e: # type: ignore
if "429" in str(e):
raise TooManyRequestsError() from e
if postprocess is not None:

View File

@ -1094,7 +1094,7 @@ def video_is_playable(video_filepath: str) -> bool:
inputs={video_filepath: None},
)
output = probe.run(stderr=subprocess.PIPE, stdout=subprocess.PIPE)
output = json.loads(output[0])
output = json.loads(output[0]) # type: ignore
video_codec = output["streams"][0]["codec_name"]
return (container, video_codec) in [
(".mp4", "h264"),

View File

@ -6,8 +6,6 @@ source scripts/helpers.sh
pip_required
echo "Creating test requirements...
To match the CI environment, this script should be run from a Unix-like system in Python 3.9."
To match the CI environment, this script should be run from a Unix-like system in Python 3.10."
cd test
pip install --upgrade pip-tools
pip-compile requirements.in --output-file requirements.txt
uv pip compile test/requirements.in -o test/requirements.txt

View File

@ -1,13 +1,17 @@
# Don't forget to run bash scripts/create_test_requirements.sh and scripts/create_test_requirements-37.sh from unix or wsl when you update this file.
# Make sure the gradio version is less than the one in gradio/package.json so that it can be overridden by the local version.
IPython
altair
asyncio
boto3
coverage
fastapi>=0.101.0
gradio_pdf==0.0.3
fastapi>=0.115.7
gradio_pdf==0.0.21
gradio==5.10.0
matplotlib
httpx
huggingface_hub
hypothesis
polars==0.20.5
pydantic[email]
pytest

View File

@ -1,125 +1,127 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
#
# This file was autogenerated by uv via the following command:
# uv pip compile test/requirements.in -o test/requirements.txt
aiofiles==23.2.1
# via gradio
altair>=5.0
# via
# -r requirements.in
# gradio
annotated-types==0.6.0
altair==5.5.0
# via -r test/requirements.in
annotated-types==0.7.0
# via pydantic
anyio==3.6.1
anyio==4.8.0
# via
# httpcore
# gradio
# httpx
# starlette
appnope==0.1.4
# via ipython
asttokens==3.0.0
# via stack-data
asyncio==3.4.3
# via -r requirements.in
attrs==23.1.0
# via -r test/requirements.in
attrs==25.1.0
# via
# hypothesis
# jsonschema
# pytest
backcall==0.2.0
# via ipython
boto3==1.34.84
# via -r requirements.in
botocore==1.34.84
# referencing
boto3==1.36.8
# via -r test/requirements.in
botocore==1.36.8
# via
# boto3
# s3transfer
certifi==2022.6.15
certifi==2024.12.14
# via
# httpcore
# httpx
# requests
charset-normalizer==2.1.0
charset-normalizer==3.4.1
# via requests
click==8.1.7
click==8.1.8
# via
# typer
# uvicorn
colorama==0.4.6
# via typer
contourpy==1.0.7
contourpy==1.3.1
# via matplotlib
coverage[toml]==7.4.2
coverage==7.6.10
# via
# -r requirements.in
# -r test/requirements.in
# pytest-cov
cycler==0.12.1
# via matplotlib
decorator==5.1.1
# via ipython
diffusers==0.30.3
# via -r requirements.in
dnspython==2.6.1
diffusers==0.32.2
# via -r test/requirements.in
dnspython==2.7.0
# via email-validator
email-validator==2.1.0.post1
email-validator==2.2.0
# via pydantic
entrypoints==0.4
# via altair
fastapi==0.103.0
executing==2.2.0
# via stack-data
fastapi==0.115.7
# via
# -r requirements.in
# -r test/requirements.in
# gradio
ffmpy==0.3.2
ffmpy==0.5.0
# via gradio
filelock==3.7.1
filelock==3.17.0
# via
# diffusers
# huggingface-hub
# torch
# transformers
fonttools==4.49.0
fonttools==4.55.7
# via matplotlib
fsspec==2024.2.0
fsspec==2024.12.0
# via
# gradio-client
# huggingface-hub
# torch
gradio-client==0.10.0
gradio==5.10.0
# via
# -r test/requirements.in
# gradio-pdf
gradio-client==1.5.3
# via gradio
gradio-pdf==0.0.7
# via -r requirements.in
gradio-pdf==0.0.21
# via -r test/requirements.in
h11==0.14.0
# via
# httpcore
# uvicorn
httpcore==1.0.5
httpcore==1.0.7
# via httpx
httpx==0.28.1
# via
# -r requirements.in
# -r test/requirements.in
# gradio
# gradio-client
# respx
hypothesis==6.108.9
idna==3.3
# safehttpx
huggingface-hub==0.28.0
# via
# -r test/requirements.in
# diffusers
# gradio
# gradio-client
# tokenizers
# transformers
hypothesis==6.124.7
# via -r test/requirements.in
idna==3.10
# via
# anyio
# email-validator
# httpx
# requests
# rfc3986
imageio==2.19.5
imageio==2.37.0
# via scikit-image
importlib-metadata==7.0.1
importlib-metadata==8.6.1
# via diffusers
importlib-resources==6.1.1
# via
# gradio
# matplotlib
iniconfig==1.1.1
iniconfig==2.0.0
# via pytest
ipython==7.34.0
# via -r requirements.in
jedi==0.18.1
ipython==8.31.0
# via -r test/requirements.in
jedi==0.19.2
# via ipython
jinja2==3.1.2
jinja2==3.1.5
# via
# altair
# gradio
@ -128,65 +130,69 @@ jmespath==1.0.1
# via
# boto3
# botocore
jsonschema==4.7.2
jsonschema==4.23.0
# via altair
kiwisolver==1.4.5
jsonschema-specifications==2024.10.1
# via jsonschema
kiwisolver==1.4.8
# via matplotlib
lazy-loader==0.4
# via scikit-image
markdown-it-py==3.0.0
# via rich
markupsafe==2.1.1
markupsafe==2.1.5
# via
# gradio
# jinja2
matplotlib==3.7.5
# via gradio
matplotlib-inline==0.1.3
matplotlib==3.10.0
# via -r test/requirements.in
matplotlib-inline==0.1.7
# via ipython
mdurl==0.1.2
# via markdown-it-py
mpmath==1.3.0
# via sympy
networkx==2.6.3
narwhals==1.24.1
# via altair
networkx==3.4.2
# via
# scikit-image
# torch
numpy==1.24.4
numpy==2.2.2
# via
# altair
# contourpy
# diffusers
# gradio
# imageio
# matplotlib
# pandas
# pywavelets
# scikit-image
# scipy
# tifffile
# transformers
orjson==3.9.14
orjson==3.10.15
# via gradio
packaging==22.0
# via
# gradio
# gradio-client
# huggingface-hub
# matplotlib
# pytest
# scikit-image
# transformers
pandas==1.5.3
packaging==24.2
# via
# altair
# gradio
# gradio-client
# huggingface-hub
# lazy-loader
# matplotlib
# pytest
# pytest-rerunfailures
# scikit-image
# transformers
pandas==2.2.3
# via
# gradio
# vega-datasets
parso==0.8.3
parso==0.8.4
# via jedi
pexpect==4.8.0
pexpect==4.9.0
# via ipython
pickleshare==0.7.5
# via ipython
pillow==9.2.0
pillow==11.1.0
# via
# diffusers
# gradio
@ -196,160 +202,157 @@ pillow==9.2.0
pluggy==1.5.0
# via pytest
polars==0.20.5
# via -r requirements.in
prompt-toolkit==3.0.30
# via -r test/requirements.in
prompt-toolkit==3.0.50
# via ipython
ptyprocess==0.7.0
# via pexpect
py==1.11.0
# via pytest
pydantic[email]==2.6.1
pure-eval==0.2.3
# via stack-data
pydantic==2.10.6
# via
# -r requirements.in
# -r test/requirements.in
# fastapi
# gradio
pydantic-core==2.16.2
pydantic-core==2.27.2
# via pydantic
pydub==0.25.1
# via gradio
pygments==2.17.2
pygments==2.19.1
# via
# ipython
# rich
pyparsing==3.0.9
pyparsing==3.2.1
# via matplotlib
pyrsistent==0.18.1
# via jsonschema
pytest==8.3.2
pytest==8.3.4
# via
# -r requirements.in
# -r test/requirements.in
# pytest-asyncio
# pytest-cov
pytest-asyncio==0.19.0
# via -r requirements.in
pytest-cov==3.0.0
# via -r requirements.in
pytest-rerunfailures==14.0
# via -r requirements.in
python-dateutil==2.8.2
# pytest-rerunfailures
pytest-asyncio==0.25.3
# via -r test/requirements.in
pytest-cov==6.0.0
# via -r test/requirements.in
pytest-rerunfailures==15.0
# via -r test/requirements.in
python-dateutil==2.9.0.post0
# via
# botocore
# matplotlib
# pandas
python-multipart==0.0.9
python-multipart==0.0.20
# via gradio
pytz==2022.1
pytz==2024.2
# via pandas
pywavelets==1.3.0
# via scikit-image
pyyaml==6.0
pyyaml==6.0.2
# via
# gradio
# huggingface-hub
# transformers
regex==2022.7.9
referencing==0.36.2
# via
# jsonschema
# jsonschema-specifications
regex==2024.11.6
# via
# diffusers
# transformers
requests==2.28.1
requests==2.32.3
# via
# diffusers
# huggingface-hub
# transformers
respx==0.19.2
# via -r requirements.in
rfc3986[idna2008]==1.5.0
# via
# httpx
# rfc3986
rich==13.7.0
respx==0.22.0
# via -r test/requirements.in
rich==13.9.4
# via typer
ruff==0.4.1
rpds-py==0.22.3
# via
# -r requirements.in
# jsonschema
# referencing
ruff==0.9.3
# via
# -r test/requirements.in
# gradio
s3transfer==0.10.0
s3transfer==0.11.2
# via boto3
safetensors==0.4.2
safehttpx==0.1.6
# via gradio
safetensors==0.5.2
# via
# diffusers
# transformers
scikit-image==0.19.3
# via -r requirements.in
scipy==1.10.0
scikit-image==0.25.1
# via -r test/requirements.in
scipy==1.15.1
# via scikit-image
semantic-version==2.10.0
# via gradio
shellingham==1.5.4
# via typer
six==1.16.0
six==1.17.0
# via python-dateutil
sniffio==1.2.0
sniffio==1.3.1
# via anyio
sortedcontainers==2.4.0
# via hypothesis
stack-data==0.6.3
# via ipython
starlette==0.45.3
# via
# anyio
# httpcore
# httpx
starlette==0.27.0
# via fastapi
sympy==1.12
# fastapi
# gradio
sympy==1.13.1
# via torch
tifffile==2021.11.2
tifffile==2025.1.10
# via scikit-image
tokenizers==0.15.1
tokenizers==0.21.0
# via transformers
tomli==2.0.1
# via
# coverage
# pytest
tomlkit==0.12.0
tomlkit==0.13.2
# via gradio
toolz==0.12.0
# via altair
torch==2.1.2
# via -r requirements.in
tqdm==4.64.0
torch==2.6.0
# via -r test/requirements.in
tqdm==4.67.1
# via
# -r requirements.in
# -r test/requirements.in
# huggingface-hub
# transformers
traitlets==5.3.0
traitlets==5.14.3
# via
# ipython
# matplotlib-inline
transformers==4.37.2
# via -r requirements.in
typer[all]==0.9.0
# via
# gradio
# typer
typing-extensions==4.9.0
transformers==4.48.1
# via -r test/requirements.in
typer==0.15.1
# via gradio
typing-extensions==4.12.2
# via
# altair
# anyio
# fastapi
# gradio
# gradio-client
# huggingface-hub
# ipython
# pydantic
# pydantic-core
# starlette
# referencing
# torch
# typer
# uvicorn
urllib3==1.26.10
tzdata==2025.1
# via pandas
urllib3==2.3.0
# via
# botocore
# requests
uvicorn==0.27.1
uvicorn==0.34.0
# via gradio
vega-datasets==0.9.0
# via -r requirements.in
wcwidth==0.2.5
# via -r test/requirements.in
wcwidth==0.2.13
# via prompt-toolkit
websockets==11.0.3
websockets==14.2
# via gradio-client
zipp==3.17.0
# via
# importlib-metadata
# importlib-resources
# The following packages are considered to be unsafe in a requirements file:
# setuptools
zipp==3.21.0
# via importlib-metadata

View File

@ -11,8 +11,7 @@ from gradio_pdf import PDF
def test_processing_utils_backwards_compatibility():
pdf_component = PDF()
cached_pdf_file = pdf_component.as_example("test/test_files/sample_file.pdf")
path = cached_pdf_file.path # type: ignore
assert (
cached_pdf_file
and Path(cached_pdf_file).exists()
and Path(cached_pdf_file).name == "sample_file.pdf"
cached_pdf_file and Path(path).exists() and Path(path).name == "sample_file.pdf"
)

View File

@ -340,7 +340,7 @@ class TestThemeUploadDownload:
def test_first_upload_no_version(self, mock_1):
mock_1.whoami.return_value = {"name": "freddyaboulton"}
mock_1.HfApi().space_info.side_effect = huggingface_hub.hf_api.HTTPError("Foo")
mock_1.HfApi().space_info.side_effect = huggingface_hub.hf_api.HTTPError("Foo") # type: ignore
gr.themes.Monochrome().push_to_hub(repo_name="does_not_exist")
repo_call_args = mock_1.HfApi().create_commit.call_args_list[0][1]