Spaces:
No application file
No application file
Download app.js from AILabDec4/Dec4SpaceE: direct link, hf CLI and curl.
- Browser
- Download file 765 Bytes
-
https://huggingface.co/spaces/AILabDec4/Dec4SpaceE/resolve/main/app.js
- Command line
-
hf download hf://spaces/AILabDec4/Dec4SpaceE/app.js
-
curl -L -o app.js https://huggingface.co/spaces/AILabDec4/Dec4SpaceE/resolve/main/app.js
765 Bytes
| import tensorflow as tf | |
| from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2, preprocess_input, decode_predictions | |
| from PIL import Image | |
| import numpy as np | |
| import gradio as gr | |
| # Load pre-trained MobileNetV2 model | |
| model = MobileNetV2(weights='imagenet') | |
| def classify_image(inp): | |
| inp = inp.reshape((-1, 224, 224, 3)) | |
| inp = preprocess_input(inp) | |
| prediction = model.predict(inp).flatten() | |
| return decode_predictions(np.array([prediction]), top=5)[0] | |
| # Define Gradio interface | |
| image_input = gr.inputs.Image(shape=(224, 224)) | |
| label_output = gr.outputs.Label(num_top_classes=5) | |
| interface = gr.Interface(fn=classify_image, inputs=image_input, outputs=label_output) | |
| # Launch the application | |
| if __name__ == "__main__": | |
| interface.launch() |