ppicazo commited on
Commit
749fb72
·
verified ·
1 Parent(s): 7deff95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -1,14 +1,24 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- pipeline = pipeline(task="image-classification", model="bortle/moon-detector-v5.a")
5
 
6
  def predict(image):
7
- predictions = pipeline(image)
8
- return {p["label"]: p["score"] for p in predictions}
 
 
 
 
 
 
 
 
 
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",