broyang commited on
Commit
ff237ab
1 Parent(s): 1539dfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -39
app.py CHANGED
@@ -1,16 +1,9 @@
1
- import sys
2
  import cv2
3
  import numpy as np
4
  import math
5
  from PIL import Image, ImageDraw, ImageFont, ImageOps
6
  Image.MAX_IMAGE_PIXELS = None
7
  import gradio as gr
8
- import shutil
9
-
10
- if len(sys.argv) > 1:
11
- res_path = sys.argv[1]
12
- else:
13
- res_path = "C:/3DM/longcrash"
14
 
15
  def get_exif(image_path):
16
  try:
@@ -90,11 +83,11 @@ def draw_scale_bar(right_img, exif_data, compass, line_img, paste_x_position, pa
90
  # Draw scale bar
91
  draw = ImageDraw.Draw(right_img)
92
  try:
93
- font = ImageFont.truetype("DejaVuSans.ttf", font_size)
94
  print("loaded font")
95
  except IOError:
96
  font = ImageFont.load_default()
97
- print("default")
98
  section_width = scale_bar_width_px / 4
99
  section_x_position = x_position - 1 * section_width #base 0 incremental position
100
  text_position = (section_x_position + section_width - font_size / 4, y_position - font_size - 20)
@@ -120,7 +113,7 @@ def draw_scale_bar(right_img, exif_data, compass, line_img, paste_x_position, pa
120
 
121
  #feet per inch
122
  try:
123
- font = ImageFont.truetype("DejaVuSans.ttf", int(font_size * 1.3))
124
  except IOError:
125
  font = ImageFont.load_default()
126
  dpi = calculate_dpi(pixel_scale_x, latitude)
@@ -202,32 +195,8 @@ def create_line_drawing(input_path):
202
  sb_logo = Image.open("./SB_logo_horizontal.png")
203
  compass = Image.open("./compass.jpg")
204
 
205
- # local testing
206
- # demo.queue().launch(share=False, server_name="0.0.0.0", server_port=8080, concurrency_count=1)
207
- # demo = gr.Interface(create_line_drawing,
208
- # inputs=gr.File(type="filepath", label="Image"),
209
- # outputs="image",
210
- # live=True)
211
-
212
- def get_file(fileobj):
213
- file_path = fileobj.name
214
- return file_path
215
-
216
- def get_file_path(fileobj):
217
- path = "/home/ubuntu/temps/" + os.path.basename(fileobj)
218
- return shutil.copyfile(fileobj.name, path)
219
-
220
-
221
- #prod
222
- # demo = gr.Interface(create_line_drawing,
223
- # inputs=gr.File(type='filepath'),
224
- # outputs="image")
225
- # demo.queue().launch()
226
-
227
- # demo = gr.Interface(create_line_drawing,
228
- # inputs=gr.File(type="filepath", label="Image"),
229
- # outputs="image",
230
- # live=True)
231
-
232
- demo = gr.Interface(create_line_drawing, gr.File(), "image", live=True)
233
- demo.launch(show_api=False)
 
 
1
  import cv2
2
  import numpy as np
3
  import math
4
  from PIL import Image, ImageDraw, ImageFont, ImageOps
5
  Image.MAX_IMAGE_PIXELS = None
6
  import gradio as gr
 
 
 
 
 
 
7
 
8
  def get_exif(image_path):
9
  try:
 
83
  # Draw scale bar
84
  draw = ImageDraw.Draw(right_img)
85
  try:
86
+ font = ImageFont.truetype("Arial Unicode.ttf", font_size) #DejaVuSans.ttf, Arial.ttf
87
  print("loaded font")
88
  except IOError:
89
  font = ImageFont.load_default()
90
+ print("default :()")
91
  section_width = scale_bar_width_px / 4
92
  section_x_position = x_position - 1 * section_width #base 0 incremental position
93
  text_position = (section_x_position + section_width - font_size / 4, y_position - font_size - 20)
 
113
 
114
  #feet per inch
115
  try:
116
+ font = ImageFont.truetype("Arial Unicode.ttf", int(font_size * 1.3)) #DejaVuSans.ttf, Arial.ttf
117
  except IOError:
118
  font = ImageFont.load_default()
119
  dpi = calculate_dpi(pixel_scale_x, latitude)
 
195
  sb_logo = Image.open("./SB_logo_horizontal.png")
196
  compass = Image.open("./compass.jpg")
197
 
198
+ demo = gr.Interface(create_line_drawing,
199
+ inputs=gr.File(type="filepath"),
200
+ outputs="image",
201
+ live=True)
202
+ demo.queue(max_size=10).launch()