VatsalPatel18 commited on
Commit
abb70d4
1 Parent(s): 3d8f88a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -8,18 +8,25 @@ from main import load_and_preprocess_image, genomic_plip_predictions, classify_t
8
  @spaces.GPU
9
  def run_load_and_preprocess_image(image_path, clip_processor_path):
10
  image_tensor = load_and_preprocess_image(image_path, clip_processor_path)
 
 
11
  return image_tensor
12
 
13
  @spaces.GPU
14
  def run_genomic_plip_predictions(image_tensor, model_path):
 
 
15
  pred_data = genomic_plip_predictions(image_tensor, model_path)
16
  return pred_data
17
 
18
  @spaces.GPU
19
  def run_classify_tiles(pred_data, model_path):
 
 
20
  output = classify_tiles(pred_data, model_path)
21
  return output
22
 
 
23
  example_files = list(Path("sample_tiles").glob("*.jpeg"))
24
 
25
  with gr.Blocks() as demo:
@@ -35,8 +42,8 @@ with gr.Blocks() as demo:
35
  result_output = gr.Textbox(label="Result")
36
 
37
  preprocess_button = gr.Button("Preprocess Image")
38
- predict_button = gr.Button("Predict with Genomic PLIP")
39
- classify_button = gr.Button("Classify Tiles")
40
 
41
  preprocess_button.click(run_load_and_preprocess_image, inputs=[image_file, clip_processor_path], outputs=image_tensor_output)
42
  predict_button.click(run_genomic_plip_predictions, inputs=[image_tensor_output, genomic_plip_model_path], outputs=pred_data_output)
@@ -45,8 +52,8 @@ with gr.Blocks() as demo:
45
  gr.Markdown("## Step by Step Workflow")
46
  with gr.Row():
47
  preprocess_status = gr.Checkbox(label="Preprocessed Image")
48
- predict_status = gr.Checkbox(label="Predicted with Genomic PLIP")
49
- classify_status = gr.Checkbox(label="Classified Tiles")
50
 
51
  def update_status(status, result):
52
  return status, result is not None
 
8
  @spaces.GPU
9
  def run_load_and_preprocess_image(image_path, clip_processor_path):
10
  image_tensor = load_and_preprocess_image(image_path, clip_processor_path)
11
+ if image_tensor is not None:
12
+ image_tensor = image_tensor.to(torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
13
  return image_tensor
14
 
15
  @spaces.GPU
16
  def run_genomic_plip_predictions(image_tensor, model_path):
17
+ if image_tensor is None:
18
+ return None # Handle the case where image_tensor is None
19
  pred_data = genomic_plip_predictions(image_tensor, model_path)
20
  return pred_data
21
 
22
  @spaces.GPU
23
  def run_classify_tiles(pred_data, model_path):
24
+ if pred_data is None:
25
+ return "Error: Prediction data is None." # Handle the case where pred_data is None
26
  output = classify_tiles(pred_data, model_path)
27
  return output
28
 
29
+
30
  example_files = list(Path("sample_tiles").glob("*.jpeg"))
31
 
32
  with gr.Blocks() as demo:
 
42
  result_output = gr.Textbox(label="Result")
43
 
44
  preprocess_button = gr.Button("Preprocess Image")
45
+ predict_button = gr.Button("Features with Genomic PLIP")
46
+ classify_button = gr.Button("Identify Risk")
47
 
48
  preprocess_button.click(run_load_and_preprocess_image, inputs=[image_file, clip_processor_path], outputs=image_tensor_output)
49
  predict_button.click(run_genomic_plip_predictions, inputs=[image_tensor_output, genomic_plip_model_path], outputs=pred_data_output)
 
52
  gr.Markdown("## Step by Step Workflow")
53
  with gr.Row():
54
  preprocess_status = gr.Checkbox(label="Preprocessed Image")
55
+ predict_status = gr.Checkbox(label="Features with Genomic PLIP")
56
+ classify_status = gr.Checkbox(label="Identify Risk")
57
 
58
  def update_status(status, result):
59
  return status, result is not None