ppicazo commited on
Commit
65e3903
·
verified ·
1 Parent(s): 0efb21e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+
5
+ model_pipeline = pipeline(task="image-classification", model="ppicazo/allsky-stars-detected")
6
+
7
+ def predict(image):
8
+ # Resize the image to have width 1080 while keeping aspect ratio
9
+ width = 1080
10
+ ratio = width / image.width
11
+ height = int(image.height * ratio)
12
+ resized_image = image.resize((width, height))
13
+
14
+ # Perform predictions
15
+ predictions = model_pipeline(resized_image)
16
+
17
+ # Return predictions as a dictionary
18
+ return {p["label"]: p["score"] for p in predictions}
19
+
20
+ # Define the Gradio Interface
21
+ gr.Interface(
22
+ fn=predict,
23
+ inputs=gr.Image(type="pil", label="Upload image"),
24
+ outputs=gr.Label(num_top_classes=5),
25
+ title="Star Detector",
26
+ allow_flagging="manual",
27
+ ).launch()