CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
huggingface

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: huggingface/notebooks
Path: blob/main/course/en/chapter9/section2.ipynb
Views: 2548
Kernel: Unknown Kernel

Building your first demo

Install the Transformers, Datasets, and Evaluate libraries to run this notebook.

!pip install datasets evaluate transformers[sentencepiece] !pip install gradio
import gradio as gr def greet(name): return "Hello " + name demo = gr.Interface(fn=greet, inputs="text", outputs="text") demo.launch()
import gradio as gr def greet(name): return "Hello " + name # We instantiate the Textbox class textbox = gr.Textbox(label="Type your name here:", placeholder="John Doe", lines=2) gr.Interface(fn=greet, inputs=textbox, outputs="text").launch()
from transformers import pipeline model = pipeline("text-generation") def predict(prompt): completion = model(prompt)[0]["generated_text"] return completion
import gradio as gr gr.Interface(fn=predict, inputs="text", outputs="text").launch()