foz commited on
Commit
8562cb9
1 Parent(s): 1d89ca0

Docker container

Browse files
Files changed (2) hide show
  1. Dockerfile +29 -0
  2. app_local.py +81 -0
Dockerfile ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # https://huggingface.co/spaces/sayakpaul/demo-docker-gradio/blob/main/Dockerfile
2
+
3
+ FROM python:3.9
4
+
5
+ WORKDIR /code
6
+
7
+ COPY *.py /code/
8
+
9
+ COPY ./requirements.txt /code/requirements.txt
10
+
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Set up a new user named "user" with user ID 1000
14
+ RUN useradd -m -u 1000 user
15
+
16
+ # Switch to the "user" user
17
+ USER user
18
+
19
+ # Set home to the user's home directory
20
+ ENV HOME=/home/user \
21
+ PATH=/home/user/.local/bin:$PATH
22
+
23
+ # Set the working directory to the user's home directory
24
+ WORKDIR $HOME/app
25
+
26
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
27
+ COPY --chown=user . $HOME/app
28
+
29
+ CMD ["python", "app_local.py"]
app_local.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from tifffile import imread
4
+ from PIL import Image
5
+ from path_analysis.analyse import analyse_paths
6
+ import numpy as np
7
+
8
+
9
+ # Function to preview the imported image
10
+ def preview_image(file1):
11
+ if file1:
12
+ print('Uploading image', file1.name)
13
+ im = imread(file1.name)
14
+ print(im.ndim, im.shape)
15
+ if im.ndim>2:
16
+ return Image.fromarray(np.max(im, axis=0))
17
+ else:
18
+ return Image.fromarray(im)
19
+ else:
20
+ return None
21
+
22
+
23
+ with gr.Blocks() as demo:
24
+ with gr.Row():
25
+ with gr.Column():
26
+ # Inputs for cell ID, image, and path
27
+ cellid_input = gr.Textbox(label="Cell ID", placeholder="Image_1")
28
+ image_input = gr.File(label="Input foci image")
29
+ image_preview = gr.Image(label="Max projection of foci image")
30
+ image_input.change(fn=preview_image, inputs=image_input, outputs=image_preview)
31
+ path_input = gr.File(label="SNT traces file")
32
+
33
+ # Additional options wrapped in an accordion for better UI experience
34
+ with gr.Accordion("Additional options ..."):
35
+ sphere_radius = gr.Number(label="Trace sphere radius (um)", value=0.1984125, interactive=True)
36
+ peak_threshold = gr.Number(label="Peak relative threshold", value=0.4, interactive=True)
37
+ # Resolutions for xy and z axis
38
+ with gr.Row():
39
+ xy_res = gr.Number(label='xy-yesolution (um)', value=0.0396825, interactive=True)
40
+ z_res = gr.Number(label='z resolution (um)', value=0.0909184, interactive=True)
41
+ # Resolutions for xy and z axis
42
+
43
+ threshold_type = gr.Radio(["per-trace", "per-cell"], label="Threshold-type", value="per-trace", interactive=True)
44
+ use_corrected_positions = gr.Checkbox(label="Correct foci position measurements", value=True, interactive=True)
45
+ screening_distance = gr.Number(label='Screening distance (voxels)', value=10, interactive=True)
46
+
47
+
48
+ # The output column showing the result of processing
49
+ with gr.Column():
50
+ trace_output = gr.Image(label="Overlayed paths")
51
+ image_output=gr.Gallery(label="Traced paths")
52
+ plot_output=gr.Plot(label="Foci intensity traces")
53
+ data_output=gr.DataFrame(label="Detected peak data")#, "Peak 1 pos", "Peak 1 int"])
54
+ data_file_output=gr.File(label="Output data file (.csv)")
55
+
56
+
57
+ def process(cellid_input, image_input, path_input, sphere_radius, peak_threshold, xy_res, z_res, threshold_type, use_corrected_positions, screening_distance):
58
+
59
+ config = { 'sphere_radius': sphere_radius,
60
+ 'peak_threshold': peak_threshold,
61
+ 'xy_res': xy_res,
62
+ 'z_res': z_res,
63
+ 'threshold_type': threshold_type,
64
+ 'use_corrected_positions': use_corrected_positions,
65
+ 'screening_distance': screening_distance,
66
+ }
67
+
68
+
69
+ paths, traces, fig, extracted_peaks = analyse_paths(cellid_input, image_input.name, path_input.name, config)
70
+ extracted_peaks.to_csv('output.csv')
71
+ print('extracted', extracted_peaks)
72
+ return paths, [Image.fromarray(im) for im in traces], fig, extracted_peaks, 'output.csv'
73
+
74
+
75
+ with gr.Row():
76
+ greet_btn = gr.Button("Process")
77
+ greet_btn.click(fn=process, inputs=[cellid_input, image_input, path_input, sphere_radius, peak_threshold, xy_res, z_res, threshold_type, use_corrected_positions, screening_distance], outputs=[trace_output, image_output, plot_output, data_output, data_file_output], api_name="process")
78
+
79
+
80
+ if __name__ == "__main__":
81
+ demo.launch(server_name="0.0.0.0", share=False)