Derfel2025's picture
fixed param error
963f714
raw
history blame contribute delete
835 Bytes
import gradio as gr
from transformers import pipeline
import transformers
from functools import lru_cache
@lru_cache(maxsize=4)
def get_pipeline(task: str, model_url: str):
print(f"Loading pipeline: task={task}, model={model_url}")
return pipeline(task, model=model_url)
def translate_text(task, modelUrl, chunk_to_translate):
print(transformers.__version__)
modelUrl = modelUrl.strip()
task = task.strip()
pipe = get_pipeline(task, modelUrl)
result = pipe(chunk_to_translate)
print(f"translated chunk is: {result}")
return result[0]['translation_text']
demo = gr.Interface(
fn=translate_text,
inputs=["text", "text", "text"],
outputs="text",
title="academic translator",
description="translates from academic german to English"
)
demo.launch(share=True, mcp_server=True)