test / app.py
Stephan Arrington
initial commit of a translation app
72e077d unverified
raw
history blame
1.29 kB
import gradio as gr
# Import the pipeline
from transformers import pipeline
# Define the pipeline
# Note: This pipeline is hosted on the Hugging Face model hub
# https://huggingface.co./Helsinki-NLP/opus-mt-en-he
# You can replace this with any other translation pipeline
# https://huggingface.co./models?filter=translation
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-he")
# Define a pipeline for reverse translation
# Note: This pipeline is hosted on the Hugging Face model hub
# https://huggingface.co./Helsinki-NLP/opus-mt-he-en
# You can replace this with any other translation pipeline
# https://huggingface.co./models?filter=translation
pipe_reverse = pipeline("translation", model="Helsinki-NLP/opus-mt-he-en")
# Define the function
def predict(text):
# Return the translation
return pipe(text)[0]["translation_text"]
def predict_reverse(text):
# Return the translation
return pipe_reverse(text)[0]["translation_text"]
# Define the interface
iface = gr.Interface(
fn=predict,
fn_reverse=predict_reverse,
inputs='text',
outputs='text',
title="English to Hebrew Translator",
description="Translate English to Hebrew",
examples=[["Hello! My name is Bob."], ["I like to eat apples and banana"]]
)
# Launch the interface
iface.launch()