oliver9523 commited on
Commit
17ba33d
·
1 Parent(s): 29dcdd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import cv2
3
  from geti_sdk.deployment import Deployment
4
  from geti_sdk.utils import show_image_with_annotation_scene
 
 
5
 
6
  # Step 1: Load the deployment
7
  deployment = Deployment.from_folder("deployment")
@@ -18,12 +20,20 @@ def resize_image(image, target_dimension):
18
  return resized_image
19
 
20
 
21
- def infer(image=None):
 
 
 
22
  if image is None:
23
- return [None,'no image']
24
-
25
- image = resize_image(image, 1200)
 
 
 
 
26
 
 
27
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
28
  prediction = deployment.infer(image)
29
  output = show_image_with_annotation_scene(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), prediction, show_results=False)
@@ -32,10 +42,14 @@ def infer(image=None):
32
 
33
 
34
  interface = gr.Interface(fn=infer,
35
- inputs='image',
36
- outputs=['image','text'],
37
  allow_flagging='manual',
38
  flagging_dir='flagged',
39
- examples=["no_bird.jpg", "bird_example.jpg"])
 
 
 
 
40
 
41
- interface.launch()
 
2
  import cv2
3
  from geti_sdk.deployment import Deployment
4
  from geti_sdk.utils import show_image_with_annotation_scene
5
+ import numpy as np
6
+ from urllib.request import urlopen
7
 
8
  # Step 1: Load the deployment
9
  deployment = Deployment.from_folder("deployment")
 
20
  return resized_image
21
 
22
 
23
+ def infer(image=None, url:str=None):
24
+ if image is None and url is None:
25
+ return [None,'no image or URL provided']
26
+
27
  if image is None:
28
+ if isinstance(url, str):
29
+ req = urlopen(url)
30
+ arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
31
+ image = cv2.imdecode(arr, -1)
32
+ if image is None:
33
+ return [None, f'Unable to fetch image from {url}']
34
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
35
 
36
+ image = resize_image(image, 1200)
37
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
38
  prediction = deployment.infer(image)
39
  output = show_image_with_annotation_scene(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), prediction, show_results=False)
 
42
 
43
 
44
  interface = gr.Interface(fn=infer,
45
+ inputs=['image', 'text'],
46
+ outputs=['image', 'text'],
47
  allow_flagging='manual',
48
  flagging_dir='flagged',
49
+ examples=[["no_bird.jpg", ""],
50
+ ["bird_example.jpg",""],
51
+ [None,"https://upload.wikimedia.org/wikipedia/commons/9/9a/Pinz%C3%B3n_azul_de_Gran_Canaria_%28macho%29%2C_M._A._Pe%C3%B1a.jpg"]
52
+ [None, "https://upload.wikimedia.org/wikipedia/commons/2/2f/Phaethon_lepturus_%28Warwick%2C_Bermuda%29_%28cropped%29.jpg"]
53
+ ])
54
 
55
+ interface.launch()