Spaces:
Runtime error
Runtime error
File size: 1,383 Bytes
db58511 74248bf db58511 74248bf db58511 74248bf bc5bba3 db58511 |
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 47 |
#installing the gradio transformer
#!pip install -q gradio git+https://github.com/huggingface/transformers gradio torch
import gradio as gr
#from transformers import AutoModelForSeq2SeqLM, pipeline
#import torch
import json
#from transformers import T5ForConditionalGeneration
import T5
# this model was loaded from https://hf.co/models
model = T5('t5-small').to('cuda')
LANGS = ["English", "German", "Italian", "Dutch", "Romanian", "French"]
# Load the weights
with open("config.json", "r") as f:
config = json.load(f)
model.load_state_dict(torch.load(config["weight"]))
def translate(text, src_lang, tgt_lang):
"""
Translate the text from source lang to target lang
"""
inputs = ["translate "+src_lang+" to "+tgt_lang+": "+text]
with torch.inference_mode():
outputs = model.predict(inputs)
return outputs[0]
demo = gr.Interface(
fn=translate,
inputs=[
gr.components.Textbox(label="Text"),
gr.components.Dropdown(label="Source Language", choices=LANGS),
gr.components.Dropdown(label="Target Language", choices=LANGS),
],
outputs=["text"],
#examples=[["Building a translation demo with Gradio is so easy!", "eng_Latn", "spa_Latn"]],
cache_examples=False,
title="Language Translator",
description="This is a GUI for the Language Translation System"
)
demo.launch(share=True) |