Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbook recipe for demos with Gradio. #133

Merged
merged 22 commits into from
Jul 8, 2024

Conversation

dmaniloff
Copy link
Member

What does this PR do?

Recipe to create demos with Gradio for the HF Enterprise Cookbook.

Who can review?

@stevhliu

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@dmaniloff
Copy link
Member Author

cc/ @MoritzLaurer

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
@@ -0,0 +1,5796 @@
{
Copy link
Collaborator

@merveenoyan merveenoyan Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW one thing cool about gradio is it has direct integration with transformers, so you can call gr.Interface.load() here instead of calling pipeline and then Interface. and for more complex second part you could do a bare function and then pass inside Interface.


Reply via ReviewNB

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this you mean direct integration with the Hub right? Ie load works for models in the hub already.

I wanted to feature this as well (in fact it was part of my original writeup) but I ended up thinking it would make this recipe too long. Maybe I can add a TIP mention in this part to point readers to the load feature.

Copy link
Member Author

@dmaniloff dmaniloff Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this fails

gr.load(
    "distil-whisper/distil-large-v3", 
    src="models", 
    inputs=gr.Audio(type="filepath"), # "filepath" passes a str path to a temporary file containing the audio
    outputs=gr.Textbox(show_copy_button=True), # give users the option to copy the results).launch()
).launch(debug=True)

w/ the following traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/gradio/queueing.py", line 532, in process_events
    response = await route_utils.call_process_api(
  File "/usr/local/lib/python3.10/dist-packages/gradio/route_utils.py", line 276, in call_process_api
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1928, in process_api
    result = await self.call_function(
  File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1514, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/usr/local/lib/python3.10/dist-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/usr/local/lib/python3.10/dist-packages/gradio/utils.py", line 832, in wrapper
    response = f(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/gradio/external.py", line 371, in query_huggingface_inference_endpoints
    data = fn(*data)  # type: ignore
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/inference/_client.py", line 415, in automatic_speech_recognition
    response = self.post(data=audio, model=model, task="automatic-speech-recognition")
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/inference/_client.py", line 273, in post
    hf_raise_for_status(response)
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py", line 371, in hf_raise_for_status
    raise HfHubHTTPError(str(e), response=response) from e
huggingface_hub.utils._errors.HfHubHTTPError: 413 Client Error: Payload Too Large for url: https://api-inference.huggingface.co/models/distil-whisper/distil-large-v3 (Request ID: eWMj4weC7hhXnrCKf_p-d)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently in recent version of gradio this was swapped with from_pipeline which is essentially transformers integration for gradio. it doesn't need to call any API whatsoever it just loads the model and the pipeline into an Interface by inferring their i/o

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! added a TIP highlighting that constructor

notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
@@ -0,0 +1,5796 @@
{
Copy link
Collaborator

@merveenoyan merveenoyan Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the end they should call launch with no share we should mention it


Reply via ReviewNB

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you are referring to here re: share?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant one does demo.launch(share=True) when you want to set a tunnel, but this shouldn't be when gradio is ran in Spaces.

@@ -0,0 +1,5796 @@
{
Copy link
Collaborator

@merveenoyan merveenoyan Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add this at the end, I feel like further readings in middle of pages divert readers' attention a lot


Reply via ReviewNB

@@ -0,0 +1,5796 @@
{
Copy link
Collaborator

@merveenoyan merveenoyan Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add an intro to Blocks API to this recipe, it's more fundamental than features like flagging IMHO


Reply via ReviewNB

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipping this.

Copy link
Collaborator

@merveenoyan merveenoyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left very general comments, thank you for this recipe!

notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
@@ -0,0 +1,5796 @@
{
Copy link
Member

@stevhliu stevhliu Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also be nice to link directly to the text and slider components


Reply via ReviewNB

notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
notebooks/en/enterprise_cookbook_gradio.ipynb Show resolved Hide resolved
Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice demonstration of a transcription tool! 👏

notebooks/en/_toctree.yml Outdated Show resolved Hide resolved
This reverts commit bae2d39.
Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I think once the toctree is resolved, we can merge! 🥳

@stevhliu stevhliu merged commit 05199cb into huggingface:main Jul 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants