Spaces:
Sleeping
Sleeping
File size: 1,289 Bytes
65e3903 4bf29b3 65e3903 4bf29b3 65e3903 4bf29b3 65e3903 d01e3cf 4bf29b3 d01e3cf 65e3903 4bf29b3 65e3903 4bf29b3 |
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 |
import gradio as gr
from transformers import pipeline
from PIL import Image
# Load both models
model_pipeline_v1 = pipeline(task="image-classification", model="ppicazo/allsky-stars-detected")
model_pipeline_v2 = pipeline(task="image-classification", model="ppicazo/allsky-stars-detected-v2")
def predict(image):
# Resize the image to have width 1080 while keeping the aspect ratio
width = 1080
ratio = width / image.width
height = int(image.height * ratio)
resized_image = image.resize((width, height))
# Perform predictions with both models
predictions_v1 = model_pipeline_v1(resized_image)
predictions_v2 = model_pipeline_v2(resized_image)
# Format the results for each model
results_v1 = {p["label"]: p["score"] for p in predictions_v1}
results_v2 = {p["label"]: p["score"] for p in predictions_v2}
# Return results as separate outputs
return results_v1, results_v2
# Define the Gradio Interface
gr.Interface(
fn=predict,
inputs=gr.Image(type="pil", label="Upload image"),
outputs=[
gr.Label(num_top_classes=5, label="Model v1 Predictions"),
gr.Label(num_top_classes=5, label="Model v2 Predictions"),
],
title="Star Detector (Two Models)",
allow_flagging="manual",
).launch()
|