HarryEslick commited on
Commit
8228fe3
·
1 Parent(s): 07ce6e4

asset path and logging

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -28,16 +28,30 @@ import plotly.express as px
28
  from spatstatapp.inference import inference_large
29
  from spatstatapp.plotting import coco_to_detections
30
  from spatstatapp.tile_training_data import load_bboxes
 
31
 
32
  import gradio as gr
33
  import numpy as np
34
  from PIL import Image, ImageDraw
35
  import cv2
 
 
 
 
 
36
 
37
  # %% load image and detections |
38
- model_path = Path("models/best.pt")
39
 
40
- data_dir=Path("img")
 
 
 
 
 
 
 
 
 
41
  data_dir.exists()
42
 
43
  train_images = list(data_dir.glob('shells.png'))
@@ -388,5 +402,12 @@ with gr.Blocks(
388
 
389
 
390
  if __name__ == "__main__":
391
- demo.launch()
 
 
 
 
 
 
 
392
 
 
28
  from spatstatapp.inference import inference_large
29
  from spatstatapp.plotting import coco_to_detections
30
  from spatstatapp.tile_training_data import load_bboxes
31
+ import os
32
 
33
  import gradio as gr
34
  import numpy as np
35
  from PIL import Image, ImageDraw
36
  import cv2
37
+ import logging
38
+
39
+ # Configure logging
40
+ logging.basicConfig(level=logging.INFO)
41
+ logger = logging.getLogger(__name__)
42
 
43
  # %% load image and detections |
 
44
 
45
+ def get_asset_path(relative_path):
46
+ if os.getenv('SPACE_ID'):
47
+ # Running on HF Spaces
48
+ return os.path.join(os.getcwd(), relative_path)
49
+ # Running locally
50
+ return relative_path
51
+
52
+ model_path = get_asset_path(Path("models/best.pt"))
53
+
54
+ data_dir=get_asset_path(Path("img"))
55
  data_dir.exists()
56
 
57
  train_images = list(data_dir.glob('shells.png'))
 
402
 
403
 
404
  if __name__ == "__main__":
405
+ demo.launch(
406
+ server_name="0.0.0.0",
407
+ server_port=7860,
408
+ show_error=True,
409
+ debug=True,
410
+ share=True
411
+ )
412
+
413