ReyaLabColumbia commited on
Commit
2fbadd4
·
verified ·
1 Parent(s): 8f90176

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -31
app.py CHANGED
@@ -1,37 +1,57 @@
1
  import gradio as gr
2
- import Colony_Analyzer_AI2_HF as analyzer
3
  from PIL import Image
4
- import cv2
5
- import numpy as np
6
 
7
- #this one I know works with just the basic imaging functionality
8
-
9
- # Analysis function adapted from your Tkinter app
10
  def analyze_image(image, min_size, circularity):
11
- print(type(image))
12
- print(len(image))
13
- # Assume your analyzer.main accepts [image, params] format, adjust as needed
14
- processed_img,picname, excelname = analyzer.main([image, min_size, circularity])
15
- #print(type(processed_img))
16
- # Convert back to RGB for display
17
- #result = cv2.cvtColor(processed_img, cv2.COLOR_BGR2RGB)
 
 
 
 
 
18
  return Image.fromarray(processed_img), picname, excelname
19
 
20
- # Create Gradio interface
21
- iface = gr.Interface(
22
- fn=analyze_image,
23
- inputs=[
24
- gr.Image(type="pil", label="Upload Image"),
25
- gr.Number(label="Minimum Colony Size (pixels)", value=1000),
26
- gr.Number(label="Minimum Circularity", value=0.25)
27
- ],
28
- outputs=[
29
- gr.Image(type="pil", label="Analyzed Image"),
30
- gr.File(label="Download Image"),
31
- gr.File(label="Download results (Excel)")
32
- ],
33
- title="AI Colony Analyzer",
34
- description="Upload an image to run the colony analysis."
35
- )
36
-
37
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
2
  from PIL import Image
 
 
3
 
4
+ # Single image analysis function (your existing logic)
 
 
5
  def analyze_image(image, min_size, circularity):
6
+ import Colony_Analyzer_AI2_HF as analyzer
7
+ processed_img, picname, excelname = analyzer.main([image, min_size, circularity])
8
+ return Image.fromarray(processed_img), picname, excelname
9
+
10
+ # Z-stack analysis function (adapt with your own logic)
11
+ def analyze_zstack(images, min_size, circularity):
12
+ # images: list of PIL images
13
+ # Plug in your own z-stack segmentation logic here
14
+ # Example stub: pass images as a list to your analyzer
15
+ import Colony_Analyzer_AI_zstack2_HF as analyzer
16
+ images = [Image.open(f.name) for f in images]
17
+ processed_img, picname, excelname = analyzer.main([images, min_size, circularity])
18
  return Image.fromarray(processed_img), picname, excelname
19
 
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("# AI Colony Analyzer\nUpload an image (or Z-Stack) to run colony analysis.")
22
+
23
+ z_stack_checkbox = gr.Checkbox(label="Enable Z-Stack", value=False)
24
+ image_input_single = gr.Image(type="pil", label="Upload Image", visible=True)
25
+ image_input_multi = gr.File(file_count="multiple", type="file", label="Upload Z-Stack Images", visible=False)
26
+ min_size_input = gr.Number(label="Minimum Colony Size (pixels)", value=1000)
27
+ circularity_input = gr.Number(label="Minimum Circularity", value=0.25)
28
+ output_image = gr.Image(type="pil", label="Analyzed Image")
29
+ output_file_img = gr.File(label="Download Image")
30
+ output_file_excel = gr.File(label="Download results (Excel)")
31
+ process_btn = gr.Button("Process")
32
+
33
+ def toggle_inputs(z_stack_enabled):
34
+ return (
35
+ gr.update(visible=not z_stack_enabled), # single input
36
+ gr.update(visible=z_stack_enabled) # multi input
37
+ )
38
+
39
+ z_stack_checkbox.change(
40
+ toggle_inputs,
41
+ inputs=z_stack_checkbox,
42
+ outputs=[image_input_single, image_input_multi]
43
+ )
44
+
45
+ def conditional_analyze(z_stack, single_image, multi_images, min_size, circularity):
46
+ if z_stack:
47
+ return analyze_zstack(multi_images, min_size, circularity)
48
+ else:
49
+ return analyze_image(single_image, min_size, circularity)
50
+
51
+ process_btn.click(
52
+ conditional_analyze,
53
+ inputs=[z_stack_checkbox, image_input_single, image_input_multi, min_size_input, circularity_input],
54
+ outputs=[output_image, output_file_img, output_file_excel]
55
+ )
56
+
57
+ demo.launch()