ReyaLabColumbia commited on
Commit
e63ce9b
·
verified ·
1 Parent(s): 284bdef

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -50
app.py CHANGED
@@ -1,56 +1,35 @@
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
- processed_img, picname, excelname = analyzer.main([images, min_size, circularity])
17
  return Image.fromarray(processed_img), picname, excelname
18
 
19
- with gr.Blocks() as demo:
20
- gr.Markdown("# AI Colony Analyzer\nUpload an image (or Z-Stack) to run colony analysis.")
21
-
22
- z_stack_checkbox = gr.Checkbox(label="Enable Z-Stack", value=False)
23
- image_input_single = gr.Image(type="pil", label="Upload Image", visible=True)
24
- image_input_multi = gr.Image(type="pil", label="Upload Z-Stack Images", file_count="multiple", visible=False)
25
- min_size_input = gr.Number(label="Minimum Colony Size (pixels)", value=1000)
26
- circularity_input = gr.Number(label="Minimum Circularity", value=0.25)
27
- output_image = gr.Image(type="pil", label="Analyzed Image")
28
- output_file_img = gr.File(label="Download Image")
29
- output_file_excel = gr.File(label="Download results (Excel)")
30
- process_btn = gr.Button("Process")
31
-
32
- def toggle_inputs(z_stack_enabled):
33
- return (
34
- gr.update(visible=not z_stack_enabled), # single input
35
- gr.update(visible=z_stack_enabled) # multi input
36
- )
37
-
38
- z_stack_checkbox.change(
39
- toggle_inputs,
40
- inputs=z_stack_checkbox,
41
- outputs=[image_input_single, image_input_multi]
42
- )
43
-
44
- def conditional_analyze(z_stack, single_image, multi_images, min_size, circularity):
45
- if z_stack:
46
- return analyze_zstack(multi_images, min_size, circularity)
47
- else:
48
- return analyze_image(single_image, min_size, circularity)
49
-
50
- process_btn.click(
51
- conditional_analyze,
52
- inputs=[z_stack_checkbox, image_input_single, image_input_multi, min_size_input, circularity_input],
53
- outputs=[output_image, output_file_img, output_file_excel]
54
- )
55
-
56
- demo.launch()
 
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
+ # Assume your analyzer.main accepts [image, params] format, adjust as needed
12
+ processed_img,picname, excelname = analyzer.main([image, min_size, circularity])
13
+ #print(type(processed_img))
14
+ # Convert back to RGB for display
15
+ #result = cv2.cvtColor(processed_img, cv2.COLOR_BGR2RGB)
16
  return Image.fromarray(processed_img), picname, excelname
17
 
18
+ # Create Gradio interface
19
+ iface = gr.Interface(
20
+ fn=analyze_image,
21
+ inputs=[
22
+ gr.Image(type="pil", label="Upload Image"),
23
+ gr.Number(label="Minimum Colony Size (pixels)", value=1000),
24
+ gr.Number(label="Minimum Circularity", value=0.25)
25
+ ],
26
+ outputs=[
27
+ gr.Image(type="pil", label="Analyzed Image"),
28
+ gr.File(label="Download Image"),
29
+ gr.File(label="Download results (Excel)")
30
+ ],
31
+ title="AI Colony Analyzer",
32
+ description="Upload an image to run the colony analysis."
33
+ )
34
+
35
+ iface.launch()