Download app.py from NESBES/hjk: direct link, hf CLI and curl.
- Browser
- Download file 963 Bytes
-
https://huggingface.co/spaces/NESBES/hjk/resolve/main/app.py
- Command line
-
hf download hf://spaces/NESBES/hjk/app.py
-
curl -L -o app.py https://huggingface.co/spaces/NESBES/hjk/resolve/main/app.py
963 Bytes
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| model = tf.keras.applications.MobileNetV2(weights='imagenet') | |
| imagenet_labels = tf.keras.applications.mobilenet_v2.decode_predictions | |
| def classify_image(inp): | |
| inp = inp.reshape((-1, 224, 224, 3)) | |
| inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp) | |
| prediction = model.predict(inp).flatten() | |
| decoded_predictions = imagenet_labels(prediction.reshape(1, -1), top=3)[0] | |
| return {label: float(conf) for label, _, conf in decoded_predictions} | |
| iface = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.inputs.Image(shape=(224, 224)), | |
| outputs=gr.outputs.Label(num_top_classes=3), | |
| examples=["images/cheetah1.jpg", "images/lion.jpg", "images/tiger.jpg"], | |
| title="MobileNetV2 Image Classifier", | |
| description="Classifies images using a pre-trained MobileNetV2 model." | |
| ) | |
| try: | |
| iface.launch() | |
| except Exception as e: | |
| print(f"Error launching Gradio interface: {e}") |