File size: 1,079 Bytes
3b68123
daa4333
 
 
65f60ce
3b68123
daa4333
 
 
3b68123
daa4333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import os
from train_model import train
from predict_model import predict_all
os.environ['NUMPY_EXPERIMENTAL_ARRAY_FUNCTION'] = '0'

def train_model():
    train()
    return "Model trained and saved as animal_classifier_resnet.pth"

def download_model():
    return "animal_classifier_resnet.pth"

def run_predictions():
    results = predict_all()
    return "\n".join(results)

with gr.Blocks() as demo:
    gr.Markdown("# Animal Classifier Model")

    with gr.Tab("Train"):
        train_button = gr.Button("Train Model")
        train_output = gr.Textbox()
        train_button.click(train_model, outputs=train_output)

    with gr.Tab("Predict"):
        predict_button = gr.Button("Run Predictions")
        predict_output = gr.Textbox()
        predict_button.click(run_predictions, outputs=predict_output)

    with gr.Tab("Download"):
        gr.Markdown("## Download Trained Model")
        download_button = gr.Button("Download Model")
        download_button.click(download_model, outputs=gr.File())

if __name__ == "__main__":
    demo.launch()