perkan commited on
Commit
4fd6f84
·
verified ·
1 Parent(s): 66c7b56

Uploading basic page for model comparison.

Browse files

I am adding the basic code for having the basic model next to the fine-tuned models.

Files changed (1) hide show
  1. app.py +38 -12
app.py CHANGED
@@ -1,18 +1,44 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
 
 
 
5
 
6
- def predict(input_img):
7
- predictions = pipeline(input_img)
8
- return input_img, {p["label"]: p["score"] for p in predictions}
9
 
10
- gradio_app = gr.Interface(
11
- predict,
12
- inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
13
- outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
14
- title="Hot Dog? Or Not?",
15
- )
 
 
 
16
 
17
- if __name__ == "__main__":
18
- gradio_app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()