Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the image classification model from Hugging Face | |
| classifier = pipeline("image-classification", model="microsoft/resnet-50") | |
| def classify_image(image): | |
| # Perform image classification | |
| results = classifier(image) | |
| # Format the results | |
| return {result["label"]: f"{result['score']:.4f}" for result in results} | |
| # Create the Gradio interface | |
| demo = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label(num_top_classes=5), | |
| title="Image Classification with ResNet-50", | |
| description="Upload an image to classify it into one of 1000 ImageNet categories." | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() | |