Spaces:
Sleeping
Sleeping
p[
Browse files
app.py
CHANGED
|
@@ -13,21 +13,21 @@ except Exception as e:
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
fine_tuned_model_1 = pipeline("translation", model="perkan/shortS-opus-mt-tc-base-en-sr")
|
| 16 |
-
print("Fine-tuned model
|
| 17 |
except Exception as e:
|
| 18 |
-
print(f"Error loading fine-tuned model
|
| 19 |
|
| 20 |
try:
|
| 21 |
fine_tuned_model_2 = pipeline("translation", model="perkan/shortM-opus-mt-tc-base-en-sr")
|
| 22 |
-
print("Fine-tuned model
|
| 23 |
except Exception as e:
|
| 24 |
-
print(f"Error loading fine-tuned model
|
| 25 |
|
| 26 |
try:
|
| 27 |
fine_tuned_model_3 = pipeline("translation", model="perkan/shortL-opus-mt-tc-base-en-sr")
|
| 28 |
-
print("Fine-tuned model
|
| 29 |
except Exception as e:
|
| 30 |
-
print(f"Error loading fine-tuned model
|
| 31 |
|
| 32 |
# Define translation functions
|
| 33 |
def translate_base(text):
|
|
@@ -38,11 +38,11 @@ def translate_base(text):
|
|
| 38 |
|
| 39 |
def translate_fine_tuned(text, model):
|
| 40 |
try:
|
| 41 |
-
if model == '
|
| 42 |
return fine_tuned_model_1(text)[0]['translation_text']
|
| 43 |
-
elif model == '
|
| 44 |
return fine_tuned_model_2(text)[0]['translation_text']
|
| 45 |
-
elif model == '
|
| 46 |
return fine_tuned_model_3(text)[0]['translation_text']
|
| 47 |
else:
|
| 48 |
return "Invalid model selected"
|
|
@@ -64,7 +64,7 @@ with gr.Blocks() as demo:
|
|
| 64 |
with gr.Column():
|
| 65 |
gr.Markdown("### Fine-tuned Models")
|
| 66 |
fine_tuned_input = gr.Textbox(placeholder="Enter text to translate", label="Input")
|
| 67 |
-
model_select = gr.Dropdown(choices=["
|
| 68 |
fine_tuned_output = gr.Textbox(label="Translation")
|
| 69 |
fine_tuned_translate_btn = gr.Button("Translate")
|
| 70 |
fine_tuned_translate_btn.click(translate_fine_tuned, inputs=[fine_tuned_input, model_select], outputs=fine_tuned_output)
|
|
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
fine_tuned_model_1 = pipeline("translation", model="perkan/shortS-opus-mt-tc-base-en-sr")
|
| 16 |
+
print("Fine-tuned model S loaded successfully.")
|
| 17 |
except Exception as e:
|
| 18 |
+
print(f"Error loading fine-tuned model S: {e}")
|
| 19 |
|
| 20 |
try:
|
| 21 |
fine_tuned_model_2 = pipeline("translation", model="perkan/shortM-opus-mt-tc-base-en-sr")
|
| 22 |
+
print("Fine-tuned model M loaded successfully.")
|
| 23 |
except Exception as e:
|
| 24 |
+
print(f"Error loading fine-tuned model M: {e}")
|
| 25 |
|
| 26 |
try:
|
| 27 |
fine_tuned_model_3 = pipeline("translation", model="perkan/shortL-opus-mt-tc-base-en-sr")
|
| 28 |
+
print("Fine-tuned model L loaded successfully.")
|
| 29 |
except Exception as e:
|
| 30 |
+
print(f"Error loading fine-tuned model L: {e}")
|
| 31 |
|
| 32 |
# Define translation functions
|
| 33 |
def translate_base(text):
|
|
|
|
| 38 |
|
| 39 |
def translate_fine_tuned(text, model):
|
| 40 |
try:
|
| 41 |
+
if model == 'S model':
|
| 42 |
return fine_tuned_model_1(text)[0]['translation_text']
|
| 43 |
+
elif model == 'M model':
|
| 44 |
return fine_tuned_model_2(text)[0]['translation_text']
|
| 45 |
+
elif model == 'L model':
|
| 46 |
return fine_tuned_model_3(text)[0]['translation_text']
|
| 47 |
else:
|
| 48 |
return "Invalid model selected"
|
|
|
|
| 64 |
with gr.Column():
|
| 65 |
gr.Markdown("### Fine-tuned Models")
|
| 66 |
fine_tuned_input = gr.Textbox(placeholder="Enter text to translate", label="Input")
|
| 67 |
+
model_select = gr.Dropdown(choices=["S model", "M model", "L model"], label="Select Model")
|
| 68 |
fine_tuned_output = gr.Textbox(label="Translation")
|
| 69 |
fine_tuned_translate_btn = gr.Button("Translate")
|
| 70 |
fine_tuned_translate_btn.click(translate_fine_tuned, inputs=[fine_tuned_input, model_select], outputs=fine_tuned_output)
|