Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| import transformers | |
| from functools import lru_cache | |
| 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) |