Buckets:
| # Compartir demos con otras personas[[sharing-demos-with-others]] | |
| Las demos de Gradio pueden compartirse de dos maneras: usando un **enlace temporal para compartir** o mediante **alojamiento permanente en Spaces**. | |
| ### Pulir tu demo de Gradio[[polishing-your-gradio-demo]] | |
| La clase `Interface` admite varios parámetros opcionales útiles: `title`, `description`, `article`, `theme`, `examples` y `live`. | |
| ```py | |
| title = "Ask Rick a Question" | |
| description = """ | |
| The bot was trained to answer questions based on Rick and Morty dialogues. Ask Rick anything! | |
| """ | |
| article = "Check out [the original Rick and Morty Bot](https://huggingface.co/spaces/kingabzpro/Rick_and_Morty_Bot) that this demo is based off of." | |
| gr.Interface( | |
| fn=predict, | |
| inputs="textbox", | |
| outputs="text", | |
| title=title, | |
| description=description, | |
| article=article, | |
| examples=[["What are you doing?"], ["Where should we time travel to?"]], | |
| ).launch() | |
| ``` | |
| ### Compartir tu demo con enlaces temporales[[sharing-your-demo-with-temporary-links]] | |
| Puedes compartir la interfaz públicamente con: | |
| ```py | |
| gr.Interface(classify_image, "image", "label").launch(share=True) | |
| ``` | |
| Esto crea un enlace público temporal que otras personas pueden abrir en su navegador. | |
| ### Alojar tu demo en Hugging Face Spaces[[hosting-your-demo-on-hugging-face-spaces]] | |
| Para un despliegue permanente, Hugging Face Spaces te permite alojar tu demo gratis. El código de la interfaz vive normalmente en un archivo `app.py` dentro del repositorio del Space. | |
| ## ✏️ ¡Pongámoslo en práctica![[lets-apply-it]] | |
| Aquí tienes un ejemplo de una demo de reconocimiento de bocetos con Gradio: | |
| ```py | |
| from pathlib import Path | |
| import torch | |
| import gradio as gr | |
| from torch import nn | |
| LABELS = Path("class_names.txt").read_text().splitlines() | |
| model = nn.Sequential( | |
| nn.Conv2d(1, 32, 3, padding="same"), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Conv2d(32, 64, 3, padding="same"), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Conv2d(64, 128, 3, padding="same"), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Flatten(), | |
| nn.Linear(1152, 256), | |
| nn.ReLU(), | |
| nn.Linear(256, len(LABELS)), | |
| ) | |
| ``` | |
| Y su interfaz: | |
| ```py | |
| interface = gr.Interface( | |
| predict, | |
| inputs="sketchpad", | |
| outputs="label", | |
| theme="huggingface", | |
| title="Sketch Recognition", | |
| description="Who wants to play Pictionary? Draw a common object like a shovel or a laptop, and the algorithm will guess in real time!", | |
| article="Sketch Recognition | Demo Model", | |
| live=True, | |
| ) | |
| interface.launch(share=True) | |
| ``` | |
Xet Storage Details
- Size:
- 2.56 kB
- Xet hash:
- ef62377714ef2982f9c5f2b350be189e0e0954cbc060aa3978d8b2ddcd6e0208
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.