Spaces:
Sleeping
Sleeping
Uploading basic page for model comparison.
Browse filesI am adding the basic code for having the basic model next to the fine-tuned models.
app.py
CHANGED
@@ -1,18 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
return
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load models
|
5 |
+
base_model = pipeline('translation_en_to_fr', model='Helsinki-NLP/opus-mt-en-fr')
|
6 |
+
fine_tuned_model_1 = pipeline('translation_en_to_fr', model='path/to/fine-tuned-model-1')
|
7 |
+
fine_tuned_model_2 = pipeline('translation_en_to_fr', model='path/to/fine-tuned-model-2')
|
8 |
+
fine_tuned_model_3 = pipeline('translation_en_to_fr', model='path/to/fine-tuned-model-3')
|
9 |
|
10 |
+
# Define translation functions
|
11 |
+
def translate_base(text):
|
12 |
+
return base_model(text)[0]['translation_text']
|
13 |
|
14 |
+
def translate_fine_tuned(text, model):
|
15 |
+
if model == 'model1':
|
16 |
+
return fine_tuned_model_1(text)[0]['translation_text']
|
17 |
+
elif model == 'model2':
|
18 |
+
return fine_tuned_model_2(text)[0]['translation_text']
|
19 |
+
elif model == 'model3':
|
20 |
+
return fine_tuned_model_3(text)[0]['translation_text']
|
21 |
+
else:
|
22 |
+
return "Invalid model selected"
|
23 |
|
24 |
+
# Create Gradio interface
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("### Translation Models")
|
27 |
+
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
gr.Markdown("#### Base Model")
|
31 |
+
base_input = gr.Textbox(placeholder="Enter text to translate", label="Input")
|
32 |
+
base_output = gr.Textbox(label="Translation")
|
33 |
+
base_translate_btn = gr.Button("Translate")
|
34 |
+
base_translate_btn.click(translate_base, inputs=base_input, outputs=base_output)
|
35 |
+
|
36 |
+
with gr.Column():
|
37 |
+
gr.Markdown("#### Fine-tuned Models")
|
38 |
+
fine_tuned_input = gr.Textbox(placeholder="Enter text to translate", label="Input")
|
39 |
+
model_select = gr.Dropdown(choices=["model1", "model2", "model3"], label="Select Model")
|
40 |
+
fine_tuned_output = gr.Textbox(label="Translation")
|
41 |
+
fine_tuned_translate_btn = gr.Button("Translate")
|
42 |
+
fine_tuned_translate_btn.click(translate_fine_tuned, inputs=[fine_tuned_input, model_select], outputs=fine_tuned_output)
|
43 |
+
|
44 |
+
demo.launch()
|