File size: 1,284 Bytes
009e3d6 d0220f8 03d257e 009e3d6 03d257e d0220f8 03d257e 64af1ab 03d257e 64af1ab 03d257e d0220f8 03d257e 3160c4d 515b421 d0220f8 1c5943f 03d257e 64ed549 03d257e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
from transformers import pipeline
from PIL import Image
# Load your model pipeline
model_pipeline = pipeline(
task="image-classification",
model="bortle/astrophotography-object-classifier-alpha5"
)
def predict(image):
# Resize the image to have width 1080 while keeping aspect ratio
width = 1080
ratio = width / image.width
height = int(image.height * ratio)
resized_image = image.resize((width, height))
# Perform predictions
predictions = model_pipeline(resized_image)
# Return predictions as a dictionary
return {p["label"]: p["score"] for p in predictions}
# Define the Gradio Interface
gr.Interface(
fn=predict,
inputs=gr.Image(type="pil", label="Upload Astrophotography image"),
outputs=gr.Label(num_top_classes=5),
title="Astrophotography Object Classifier",
allow_flagging="manual",
examples=[
"examples/Andromeda.jpg", "examples/Heart.jpg", "examples/Pleiades.jpg",
"examples/Rosette.jpg", "examples/Moon.jpg", "examples/GreatHercules.jpg",
"examples/Leo-Triplet.jpg", "examples/Crab.jpg", "examples/North-America.jpg",
"examples/Horsehead-Flame.jpg", "examples/Pinwheel.jpg", "examples/Saturn.jpg"
],
cache_examples=True
).launch()
|