Skip to content

Commit a58c485

Browse files
Add huggingface_hub client library (#973)
* Add huggingface_hub client library Add huggingface_hub client library and model comparator space builder section * Update guides/using_hugging_face_integrations.md Co-authored-by: Omar Sanseviero <osanseviero@gmail.com> * Apply suggestions from code review Co-authored-by: Omar Sanseviero <osanseviero@gmail.com> * tweaks Co-authored-by: Omar Sanseviero <osanseviero@gmail.com>
1 parent 5637cf9 commit a58c485

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

guides/using_hugging_face_integrations.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Using Hugging Face Integrations
22

3-
related_spaces: https://huggingface.co/spaces/osanseviero/helsinki_translation_en_es, https://huggingface.co/spaces/osanseviero/remove-bg-webcam, https://huggingface.co/spaces/mrm8488/GPT-J-6B, https://huggingface.co/spaces/akhaliq/T0pp, https://huggingface.co/spaces/osanseviero/mix_match_gradio
3+
related_spaces: https://huggingface.co/spaces/farukozderim/Model-Comparator-Space-Builder, https://huggingface.co/spaces/osanseviero/helsinki_translation_en_es, https://huggingface.co/spaces/osanseviero/remove-bg-webcam, https://huggingface.co/spaces/mrm8488/GPT-J-6B, https://huggingface.co/spaces/akhaliq/T0pp, https://huggingface.co/spaces/osanseviero/mix_match_gradio
44
tags: HUB, SPACES, EMBED
55

6-
Contributed by <a href="https://huggingface.co/osanseviero">Omar Sanseviero</a> 🦙
6+
Contributed by <a href="https://huggingface.co/osanseviero">Omar Sanseviero</a> 🦙 and <a href="https://huggingface.co/farukozderim">Ömer Faruk Özdemir</a>
77

88
## Introduction
99

@@ -140,6 +140,31 @@ iface3.launch()
140140

141141
Although both models are generative, you can see that the way both models behave is very different. That's a powerful application of `Parallel`!
142142

143+
## Creating Spaces with python
144+
145+
Making use of the [huggingface_hub client library](https://huggingface.co/docs/huggingface_hub/index) library you can create new Spaces or model repositories. You can do this even in a Gradio Space! You can find an example space [here](https://huggingface.co/spaces/farukozderim/Model-Comparator-Space-Builder). This Space creates a new Space comparing different models or spaces with the support of Gradio `load` and `Parallel`. Now you can try creating cool spaces with all kinds of functionality 😎.
146+
147+
```python
148+
from huggingface_hub import (
149+
create_repo,
150+
get_full_repo_name,
151+
upload_file,
152+
)
153+
create_repo(name=target_space_name, token=hf_token, repo_type="space", space_sdk="gradio")
154+
repo_name = get_full_repo_name(model_id=target_space_name, token=hf_token)
155+
file_url = upload_file(
156+
path_or_fileobj="file.txt",
157+
path_in_repo="app.py",
158+
repo_id=repo_name,
159+
repo_type="space",
160+
token=hf_token,
161+
)
162+
```
163+
Here, `create_repo` creates a gradio repo with the target name under a specific account using that account's Write Token. `repo_name` gets the full repo name of the related repo. Finally `upload_file` uploads a file inside the repo with the name `app.py`.
164+
165+
<iframe src="https://hf.space/embed/farukozderim/Model-Comparator-Space-Builder/+" frameBorder="0" height=800" title="Gradio app" class="container p-0 flex-grow space-iframe" allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe>
166+
167+
143168
## Embedding your Space demo on other websites
144169

145170
Throughout this guide, you've seen there are Gradio demos embedded. You can also do this on own website! The first step is to create a Space with the demo you want to showcase. You can embed it in your HTML code, as shown in the following self-contained example.
@@ -158,4 +183,4 @@ That's it! Let's recap what you can do:
158183
4. Combine multiple Spaces by running them sequentially or parallelly.
159184
5. Embed your Space demo directly on a website.
160185

161-
🤗
186+
🤗

0 commit comments

Comments
 (0)