Spaces:
Sleeping
Sleeping
File size: 1,292 Bytes
2a918d4 72e077d 2a918d4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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()
|