donb-hf commited on
Commit
464a3bb
·
1 Parent(s): bebeab0

update output path logic

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -15,19 +15,24 @@ import spaces
15
  hf_token = os.getenv("HF_TOKEN")
16
  login(token=hf_token, add_to_git_credential=True)
17
 
18
- def detect_brain_tumor(image_path: str, output_path: str, debug: bool = False) -> None:
19
  """
20
  Detects a brain tumor in the given image and saves the image with bounding boxes.
21
 
22
  Parameters:
23
- image_path (str): The path to the input image.
24
- output_path (str): The path to save the output image with bounding boxes.
25
  debug (bool): Flag to enable logging for debugging purposes.
 
 
 
26
  """
27
- # Step 1: Load the image
28
- image = load_image(image_path)
 
 
 
29
  if debug:
30
- print(f"Image loaded from {image_path}")
31
 
32
  # Step 2: Detect brain tumor using owl_v2
33
  prompt = "detect brain tumor"
@@ -44,6 +49,9 @@ def detect_brain_tumor(image_path: str, output_path: str, debug: bool = False) -
44
  save_image(image_with_bboxes, output_path)
45
  if debug:
46
  print(f"Image saved to {output_path}")
 
 
 
47
 
48
  # Example usage (uncomment to run):
49
  # detect_brain_tumor("/content/drive/MyDrive/kaggle/datasets/brain-tumor-image-dataset-semantic-segmentation_old/train_categories/1385_jpg.rf.3c67cb92e2922dba0e6dba86f69df40b.jpg", "/content/drive/MyDrive/kaggle/datasets/brain-tumor-image-dataset-semantic-segmentation_old/output/1385_jpg.rf.3c67cb92e2922dba0e6dba86f69df40b.jpg", debug=True)
@@ -65,9 +73,8 @@ with gr.Blocks(css="style.css") as demo:
65
  chat_btn = gr.Button()
66
 
67
  chat_inputs = [
68
- image,
69
- "./output/tmp.jpg",
70
- ]
71
  chat_outputs = [
72
  text_output
73
  ]
 
15
  hf_token = os.getenv("HF_TOKEN")
16
  login(token=hf_token, add_to_git_credential=True)
17
 
18
+ def detect_brain_tumor(image, debug: bool = False) -> str:
19
  """
20
  Detects a brain tumor in the given image and saves the image with bounding boxes.
21
 
22
  Parameters:
23
+ image: The input image (as a PIL Image or numpy array).
 
24
  debug (bool): Flag to enable logging for debugging purposes.
25
+
26
+ Returns:
27
+ str: Path to the saved output image.
28
  """
29
+ # Generate a unique output filename
30
+ output_path = f"./output/tumor_detection_{int(time.time())}.jpg"
31
+
32
+ # Step 1: Load the image (not needed if image is already a PIL Image or numpy array)
33
+ # image = load_image(image_path)
34
  if debug:
35
+ print(f"Image loaded")
36
 
37
  # Step 2: Detect brain tumor using owl_v2
38
  prompt = "detect brain tumor"
 
49
  save_image(image_with_bboxes, output_path)
50
  if debug:
51
  print(f"Image saved to {output_path}")
52
+
53
+ return output_path
54
+
55
 
56
  # Example usage (uncomment to run):
57
  # detect_brain_tumor("/content/drive/MyDrive/kaggle/datasets/brain-tumor-image-dataset-semantic-segmentation_old/train_categories/1385_jpg.rf.3c67cb92e2922dba0e6dba86f69df40b.jpg", "/content/drive/MyDrive/kaggle/datasets/brain-tumor-image-dataset-semantic-segmentation_old/output/1385_jpg.rf.3c67cb92e2922dba0e6dba86f69df40b.jpg", debug=True)
 
73
  chat_btn = gr.Button()
74
 
75
  chat_inputs = [
76
+ image
77
+ ]
 
78
  chat_outputs = [
79
  text_output
80
  ]