import gradio as gr from fastcore.all import * from fastai.vision.all import * import threading print('This is an info message') learn = None labels = None def load_model_async(): global learn global labels learn = load_learner('./export.pkl') labels = learn.dls.vocab # Load the model in a separate thread model_loading_thread = threading.Thread(target=load_model_async) model_loading_thread.start() # Define a function to classify an image def classify_image(file): if learn is not None and labels is not None: # Run the model to get a prediction pred_class, pred_idx, outputs = learn.predict(file) # Return the predicted class return {labels[i]: float(outputs[i]) for i in range(len(labels))} else: print('Model not loaded') # Create a Gradio interface iface = gr.Interface( fn=classify_image, inputs=gr.components.Image(label="Image"), outputs=gr.components.Label(num_top_classes=3), title="Llamalpaca-tron 5000", description="The llama-alpaca image classifier is a machine learning model designed to accurately identify whether an image contains a llama or an alpaca. Trained on a large dataset of llama and alpaca images, the model uses deep learning algorithms to analyze various features of the animals, such as their fur, body shape, and facial characteristics, and then makes a prediction based on those features. With high accuracy, this model can help identify llamas and alpacas in images, which can be useful for various applications, such as wildlife conservation, agriculture, and animal research.", ) print('This is an info message 2' ) # Run the interface iface.launch(share=False, debug=True,server_name="0.0.0.0") print('This is an info message ' )