Spaces:
Sleeping
Sleeping
Commit
·
fec4315
1
Parent(s):
fd8cd67
First setup commit
Browse files- app.py +23 -0
- backend/german_polish.py +20 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from backend.german_polish import polish_to_german_translation
|
3 |
+
|
4 |
+
#Each interface will have on input text and one output text
|
5 |
+
german_polish_interface = gr.Interface(
|
6 |
+
fn=polish_to_german_translation,
|
7 |
+
inputs=gr.Textbox(label="Polish Text"),
|
8 |
+
outputs=gr.Textbox(label="German Translation"),
|
9 |
+
title="Polish to German Translator",
|
10 |
+
description="Translate Polish toponym to German.",
|
11 |
+
)
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
tabbed_interface = gr.TabbedInterface(
|
17 |
+
[german_polish_interface],
|
18 |
+
["Polish to German Translator"],
|
19 |
+
title="Language Translation",
|
20 |
+
description="Translate text between different languages.",
|
21 |
+
)
|
22 |
+
|
23 |
+
tabbed_interface.launch()
|
backend/german_polish.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
+
import torch
|
3 |
+
|
4 |
+
model_id = "DebasishDhal99/polish-to-german-toponym-model-opus-mt-pl-de"
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
+
|
10 |
+
|
11 |
+
def polish_to_german_translation(polish_place):
|
12 |
+
inputs = tokenizer(polish_place, return_tensors="pt", padding=True, truncation=True)
|
13 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
14 |
+
|
15 |
+
|
16 |
+
with torch.no_grad():
|
17 |
+
outputs = model.generate(**inputs, max_length=50)
|
18 |
+
|
19 |
+
german_place = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
return german_place
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==5.6.0
|
2 |
+
torch==2.5.1+cu124
|
3 |
+
transformers==4.51.1
|