File size: 801 Bytes
d35357c
1b61080
2a5ba50
fc5ec97
 
b528dd0
64a9be8
2e82db6
 
 
64a9be8
 
 
ca02eb0
 
64a9be8
5fd11ce
64a9be8
b528dd0
64a9be8
 
 
 
 
b528dd0
 
64a9be8
 
 
 
 
 
b528dd0
f352d72
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
import transformers
import gradio as gr
from transformers import pipeline
import os 
TOKEN = os.getenv('HUGGING_FACE_HUB_TOKEN')

models = [
    "barghavani/English_to_French",
    "barghavani/English_to_German",
    "barghavani/English_to_Hindi",
    #"Helsinki-NLP/opus-mt-ber-fr",
    #"Helsinki-NLP/opus-mt-es-ber",
    #"Helsinki-NLP/opus-mt-ber-es",
    #"Helsinki-NLP/opus-mt-kab-en",
    #
]

pipes = {}

def predict(text, model):
    if model not in pipes:
        pipes[model] = pipeline("translation", model=model)
    pipe = pipes[model]
    return pipe(text)[0]['translation_text']

demo = gr.Interface(
    fn=predict,
    inputs=[
        gr.Textbox(lines=5, label="Input Text"),
        gr.Dropdown(models, label="Model")
    ],
    outputs='text',
)
demo.launch(share=True,debug=True)