Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| from core.predict import ImageClassifier | |
| from PIL import Image | |
| cwd = os.getcwd() | |
| model_path = os.path.join(cwd, "model", "cnn_model.pth") | |
| class_name = {0: 'Cat', 1: 'Dog', 2: 'Person'} | |
| classifier = ImageClassifier(model_path=model_path, class_name=class_name) | |
| def predict(image): | |
| image_path = "uploaded_image.jpg" | |
| image.save(image_path) | |
| label, output_image_path = classifier.predict(image_path) | |
| return label, Image.open(output_image_path) | |
| demo = gr.Interface( | |
| fn = predict, | |
| inputs = gr.Image(type="pil"), | |
| outputs = [gr.Textbox(label="Predicted Class"), gr.Image(label="Labeled Image")], | |
| title="Image Classification Gradio App", | |
| description="Upload an image to classify it as Dog, Cat or Person." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |