Mehmet Batuhan Duman commited on
Commit
e158920
·
1 Parent(s): 4ec8736

Changed scan func

Browse files
Files changed (2) hide show
  1. .idea/workspace.xml +1 -1
  2. app.py +14 -2
.idea/workspace.xml CHANGED
@@ -65,7 +65,7 @@
65
  <workItem from="1683665300392" duration="7649000" />
66
  <workItem from="1683708398011" duration="1235000" />
67
  <workItem from="1684437905081" duration="110000" />
68
- <workItem from="1686602174110" duration="4678000" />
69
  </task>
70
  <servers />
71
  </component>
 
65
  <workItem from="1683665300392" duration="7649000" />
66
  <workItem from="1683708398011" duration="1235000" />
67
  <workItem from="1684437905081" duration="110000" />
68
+ <workItem from="1686602174110" duration="5060000" />
69
  </task>
70
  <servers />
71
  </component>
app.py CHANGED
@@ -15,6 +15,7 @@ import cv2
15
  import matplotlib.pyplot as plt
16
  import matplotlib.patches as patches
17
  from functools import partial
 
18
 
19
  class Net2(nn.Module):
20
  def __init__(self):
@@ -238,11 +239,22 @@ def process_image(input_image, model, threshold=0.5):
238
  return ship_images, int(elapsed_time)
239
 
240
 
241
- def gradio_process_image(input_image_path, model, threshold=0.5):
242
  start_time = time.time()
243
- output_image_path = scanmap(input_image_path, model, threshold)
 
 
 
 
 
 
 
 
244
  elapsed_time = time.time() - start_time
245
 
 
 
 
246
  return output_image_path, f"Elapsed Time (seconds): {elapsed_time}"
247
 
248
  inputs = gr.inputs.Image(label="Upload Image")
 
15
  import matplotlib.pyplot as plt
16
  import matplotlib.patches as patches
17
  from functools import partial
18
+ import tempfile
19
 
20
  class Net2(nn.Module):
21
  def __init__(self):
 
239
  return ship_images, int(elapsed_time)
240
 
241
 
242
+ def gradio_process_image(input_image, model, threshold=0.5):
243
  start_time = time.time()
244
+
245
+ # save PIL image to a temporary file
246
+ temp = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
247
+ temp.close()
248
+ input_image.save(temp.name)
249
+
250
+ # pass file path to scanmap
251
+ output_image_path = scanmap(temp.name, model, threshold)
252
+
253
  elapsed_time = time.time() - start_time
254
 
255
+ # delete temporary file after processing
256
+ os.unlink(temp.name)
257
+
258
  return output_image_path, f"Elapsed Time (seconds): {elapsed_time}"
259
 
260
  inputs = gr.inputs.Image(label="Upload Image")