Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Load both models
|
6 |
+
model_pipeline_v1 = pipeline(task="image-classification", model="ppicazo/autotrain-ap-pass-fail-v1")
|
7 |
+
model_pipeline_v2 = pipeline(task="image-classification", model="ppicazo/allsky-stars-detected-v2")
|
8 |
+
|
9 |
+
def predict(image):
|
10 |
+
# Resize the image to have width 1080 while keeping the aspect ratio
|
11 |
+
width = 1080
|
12 |
+
ratio = width / image.width
|
13 |
+
height = int(image.height * ratio)
|
14 |
+
resized_image = image.resize((width, height))
|
15 |
+
|
16 |
+
# Perform predictions with both models
|
17 |
+
predictions_v1 = model_pipeline_v1(resized_image)
|
18 |
+
predictions_v2 = model_pipeline_v2(resized_image)
|
19 |
+
|
20 |
+
# Format the results for each model
|
21 |
+
results_v1 = {p["label"]: p["score"] for p in predictions_v1}
|
22 |
+
results_v2 = {p["label"]: p["score"] for p in predictions_v2}
|
23 |
+
|
24 |
+
# Return results as separate outputs
|
25 |
+
return results_v1, results_v2
|
26 |
+
|
27 |
+
# Define the Gradio Interface
|
28 |
+
gr.Interface(
|
29 |
+
fn=predict,
|
30 |
+
inputs=gr.Image(type="pil", label="Upload image"),
|
31 |
+
outputs=[
|
32 |
+
gr.Label(num_top_classes=5, label="Model v1 Predictions"),
|
33 |
+
gr.Label(num_top_classes=5, label="Model v2 Predictions"),
|
34 |
+
],
|
35 |
+
title="Star Detector (Two Models)",
|
36 |
+
allow_flagging="manual",
|
37 |
+
).launch()
|