Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,35 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from PIL import Image
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 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 |
-
#
|
| 11 |
-
def
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
return Image.fromarray(processed_img), picname, excelname
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|