|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
pipeline = pipeline(task="image-classification", model="bortle/astrophotography-object-classifier-alpha5") |
|
|
|
def predict(image): |
|
predictions = pipeline(image) |
|
return {p["label"]: p["score"] for p in predictions} |
|
|
|
|
|
def process_image(image): |
|
width = 1080 |
|
ratio = width / image.width |
|
height = int(image.height * ratio) |
|
resized_image = image.resize((width, height)) |
|
return resized_image |
|
|
|
gr.Interface( |
|
predict, |
|
fn=process_image, |
|
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() |