Skip to content

Instantly share code, notes, and snippets.

@osanseviero
Last active April 1, 2022 11:44
Show Gist options
  • Save osanseviero/36c66bce2b67b1da83ce248c82a18c88 to your computer and use it in GitHub Desktop.
Save osanseviero/36c66bce2b67b1da83ce248c82a18c88 to your computer and use it in GitHub Desktop.
Simple gradio demo
%%capture
!pip install gradio transformers sentencepiece
import gradio as gr
from transformers import pipeline
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
def predict(text):
return pipe(text)[0]["translation_text"]
title = "Interactive demo: Helsinki-NLP English to Spanish Translation"
iface = gr.Interface(
fn=predict,
inputs=[gr.inputs.Textbox(label="text", lines=3)],
outputs='text',
title=title,
examples=[["Hello! My name is Omar"], ["I like this workshop"]]
)
iface.launch(debug=True)
iface = gr.Interface.load("huggingface/Helsinki-NLP/opus-mt-en-es",
examples=[["Hello! My name is Omar"]]
)
iface.launch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment