Spaces:
Runtime error
Runtime error
import gradio as gr | |
import sentencepiece as spm | |
import ctranslate2 | |
description = "Translator" | |
title = "Translate!" | |
translator = ctranslate2.Translator("./", device="cpu") | |
spm_encoder = spm.SentencePieceProcessor("./en.spm.model") | |
spm_decoder = spm.SentencePieceProcessor("./ku.spm.model") | |
def translate(text): | |
tokens = spm_encoder.encode(text, out_type=str) | |
result = translator.translate_batch([tokens]) | |
output = spm_decoder.decode(result[0].hypotheses[0], out_type=str) | |
return output | |
iface = gr.Interface( | |
translate, | |
inputs="text", | |
outputs="text" | |
) | |
iface.launch() |