{ "cells": [ { "cell_type": "markdown", "id": "eed6bcd0-6cf8-4aa9-bedf-5eca5a6b7a9c", "metadata": {}, "source": [ "# Hugging Face Spaces From A Notebook" ] }, { "cell_type": "markdown", "id": "15fe30a9-cfeb-4ec0-ae40-334072046464", "metadata": {}, "source": [ "Please reference [this blog post](https://nbdev.fast.ai/blog/posts/2022-11-10-spaces) on how to use this notebook." ] }, { "cell_type": "markdown", "id": "5ca22d1e-1bd0-49c0-9b89-c480ad1a29c4", "metadata": {}, "source": [ "# Make an app with Gradio" ] }, { "cell_type": "code", "execution_count": null, "id": "00cf4fad-a920-41dc-be42-3992c7fcefac", "metadata": {}, "outputs": [], "source": [ "#|export\n", "import gradio as gr\n", "from fastcore.net import urljson, HTTPError" ] }, { "cell_type": "code", "execution_count": null, "id": "38a4389f-ef53-4626-a6f5-a859354f854b", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def size(repo:str):\n", " \"Returns the size in GB of a HuggingFace Dataset.\"\n", " url = f'https://huggingface.co/api/datasets/{repo}'\n", " try: resp = urljson(f'{url}/treesize/main')\n", " except HTTPError: return f'Did not find repo: {url}'\n", " gb = resp['size'] / 1e9\n", " return f'{gb:.2f} GB'" ] }, { "cell_type": "code", "execution_count": null, "id": "95bc32b8-d8ff-4761-a2d7-0880c51d0a42", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'5.49 GB'" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "size(\"tglcourse/CelebA-faces-cropped-128\")" ] }, { "cell_type": "code", "execution_count": null, "id": "7b20e2a1-b622-4970-9069-0202ce10a2ce", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "