Spaces:
Build error
Build error
File size: 800 Bytes
4a0c4cc 5e54914 6ae3ba4 4a0c4cc 749fb72 5e54914 749fb72 5e54914 749fb72 5e54914 749fb72 6ae3ba4 5e54914 |
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 |
import gradio as gr
from transformers import pipeline
from PIL import Image
model_pipeline = pipeline(task="image-classification", model="bortle/moon-detector-v5.a")
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 image"),
outputs=gr.Label(num_top_classes=5),
title="Moon Detector",
allow_flagging="manual",
).launch() |