Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
|
6 |
def predict(image):
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
10 |
gr.Interface(
|
11 |
-
predict,
|
12 |
inputs=gr.Image(shape=(1080, None), type="pil", label="Upload image"),
|
13 |
outputs=gr.Label(num_top_classes=5),
|
14 |
title="Moon Detector",
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
model_pipeline = pipeline(task="image-classification", model="bortle/moon-detector-v5.a")
|
5 |
|
6 |
def predict(image):
|
7 |
+
# Resize the image to have width 1080 while keeping aspect ratio
|
8 |
+
width = 1080
|
9 |
+
ratio = width / image.width
|
10 |
+
height = int(image.height * ratio)
|
11 |
+
resized_image = image.resize((width, height))
|
12 |
+
|
13 |
+
# Perform predictions
|
14 |
+
predictions = model_pipeline(resized_image)
|
15 |
+
|
16 |
+
# Return predictions as a dictionary
|
17 |
+
return {p["label"]: p["score"] for p in predictions}
|
18 |
|
19 |
+
# Define the Gradio Interface
|
20 |
gr.Interface(
|
21 |
+
fn=predict,
|
22 |
inputs=gr.Image(shape=(1080, None), type="pil", label="Upload image"),
|
23 |
outputs=gr.Label(num_top_classes=5),
|
24 |
title="Moon Detector",
|