Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
a1f9598c
Commit
a1f9598c
authored
1 year ago
by
Felipe Delestro Matos
Browse files
Options
Downloads
Patches
Plain Diff
Hotfix for annotation tool
parent
c29d9908
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
qim3d/gui/annotation_tool.py
+16
-20
16 additions, 20 deletions
qim3d/gui/annotation_tool.py
qim3d/utils/internal_tools.py
+1
-2
1 addition, 2 deletions
qim3d/utils/internal_tools.py
with
17 additions
and
22 deletions
qim3d/gui/annotation_tool.py
+
16
−
20
View file @
a1f9598c
import
tifffile
import
tifffile
import
tempfile
import
os
import
os
import
time
import
time
import
getpass
import
getpass
...
@@ -16,8 +17,7 @@ class Session:
...
@@ -16,8 +17,7 @@ class Session:
self
.
masks_rgb
=
None
self
.
masks_rgb
=
None
self
.
mask_names
=
{
0
:
"
red
"
,
1
:
"
green
"
,
2
:
"
blue
"
}
self
.
mask_names
=
{
0
:
"
red
"
,
1
:
"
green
"
,
2
:
"
blue
"
}
self
.
temp_files
=
[]
self
.
temp_files
=
[]
self
.
gradio_temp
=
None
self
.
temp_dir
=
None
self
.
username
=
getpass
.
getuser
()
class
Interface
:
class
Interface
:
...
@@ -27,6 +27,7 @@ class Interface:
...
@@ -27,6 +27,7 @@ class Interface:
self
.
height
=
768
self
.
height
=
768
self
.
interface
=
None
self
.
interface
=
None
self
.
username
=
getpass
.
getuser
()
self
.
username
=
getpass
.
getuser
()
self
.
temp_dir
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
f
"
qim-
{
self
.
username
}
"
)
# CSS path
# CSS path
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
...
@@ -34,9 +35,8 @@ class Interface:
...
@@ -34,9 +35,8 @@ class Interface:
def
launch
(
self
,
img
=
None
,
**
kwargs
):
def
launch
(
self
,
img
=
None
,
**
kwargs
):
# Create gradio interfaces
# Create gradio interfaces
# img = "/tmp/qim-fima/2dimage.png"
self
.
interface
=
self
.
create_interface
(
img
)
self
.
interface
=
self
.
create_interface
(
img
)
self
.
gradio_temp
=
self
.
interface
.
GRADIO_CACHE
# Set gradio verbose level
# Set gradio verbose level
if
self
.
verbose
:
if
self
.
verbose
:
...
@@ -55,12 +55,11 @@ class Interface:
...
@@ -55,12 +55,11 @@ class Interface:
def
get_result
(
self
):
def
get_result
(
self
):
# Get the temporary files from gradio
# Get the temporary files from gradio
base
=
os
.
path
.
join
(
self
.
gradio_temp
,
"
qim3d
"
,
self
.
username
)
temp_path_list
=
[]
temp_path_list
=
[]
for
filename
in
os
.
listdir
(
ba
se
):
for
filename
in
os
.
listdir
(
se
lf
.
temp_dir
):
if
"
mask
"
in
str
(
filename
):
if
"
mask
"
in
str
(
filename
):
# Get the list of the temporary files
# Get the list of the temporary files
temp_path_list
.
append
(
os
.
path
.
join
(
ba
se
,
filename
))
temp_path_list
.
append
(
os
.
path
.
join
(
se
lf
.
temp_dir
,
filename
))
# Make dictionary of maks
# Make dictionary of maks
masks
=
{}
masks
=
{}
...
@@ -81,7 +80,7 @@ class Interface:
...
@@ -81,7 +80,7 @@ class Interface:
else
:
else
:
custom_css
=
"
annotation-tool no-img
"
custom_css
=
"
annotation-tool no-img
"
with
gr
.
Blocks
(
css
=
self
.
css_path
)
as
gradio_interface
:
with
gr
.
Blocks
(
css
=
self
.
css_path
,
title
=
self
.
title
)
as
gradio_interface
:
brush
=
gr
.
Brush
(
brush
=
gr
.
Brush
(
colors
=
[
colors
=
[
...
@@ -126,13 +125,13 @@ class Interface:
...
@@ -126,13 +125,13 @@ class Interface:
elem_classes
=
custom_css
,
elem_classes
=
custom_css
,
)
)
temp_
path
=
gr
.
Textbox
(
value
=
gradio_interface
.
GRADIO_CACHE
,
visible
=
False
)
temp_
dir
=
gr
.
Textbox
(
value
=
self
.
temp_dir
,
visible
=
False
)
session
=
gr
.
State
([])
session
=
gr
.
State
([])
inputs
=
[
img_editor
]
inputs
=
[
img_editor
]
operations
=
Operations
()
operations
=
Operations
()
# fmt: off
# fmt: off
btn_update
.
click
(
btn_update
.
click
(
fn
=
operations
.
start_session
,
inputs
=
[
img_editor
,
temp_
path
]
,
outputs
=
session
).
then
(
fn
=
operations
.
start_session
,
inputs
=
[
img_editor
,
temp_
dir
]
,
outputs
=
session
).
then
(
fn
=
operations
.
preview
,
inputs
=
session
,
outputs
=
overlay_img
).
then
(
fn
=
operations
.
preview
,
inputs
=
session
,
outputs
=
overlay_img
).
then
(
fn
=
self
.
set_visible
,
inputs
=
None
,
outputs
=
overlay_img
).
then
(
fn
=
self
.
set_visible
,
inputs
=
None
,
outputs
=
overlay_img
).
then
(
fn
=
operations
.
separate_masks
,
inputs
=
session
,
outputs
=
[
session
,
masks_download
]).
then
(
fn
=
operations
.
separate_masks
,
inputs
=
session
,
outputs
=
[
session
,
masks_download
]).
then
(
...
@@ -147,17 +146,15 @@ class Operations:
...
@@ -147,17 +146,15 @@ class Operations:
def
start_session
(
self
,
*
args
):
def
start_session
(
self
,
*
args
):
session
=
Session
()
session
=
Session
()
session
.
img_editor
=
args
[
0
]
session
.
img_editor
=
args
[
0
]
session
.
gradio_temp
=
args
[
1
]
session
.
temp_dir
=
args
[
1
]
# Clean temp files
base
=
os
.
path
.
join
(
session
.
gradio_temp
,
"
qim3d
"
,
session
.
username
)
# Clean up old files
try
:
try
:
files
=
os
.
listdir
(
ba
se
)
files
=
os
.
listdir
(
se
ssion
.
temp_dir
)
for
filename
in
files
:
for
filename
in
files
:
# Check if "mask" is in the filename
# Check if "mask" is in the filename
if
"
mask
"
in
filename
:
if
"
mask
"
in
filename
:
file_path
=
os
.
path
.
join
(
ba
se
,
filename
)
file_path
=
os
.
path
.
join
(
se
ssion
.
temp_dir
,
filename
)
os
.
remove
(
file_path
)
os
.
remove
(
file_path
)
except
FileNotFoundError
:
except
FileNotFoundError
:
...
@@ -235,10 +232,9 @@ class Operations:
...
@@ -235,10 +232,9 @@ class Operations:
if
np
.
sum
(
mask
)
>
0
:
if
np
.
sum
(
mask
)
>
0
:
mask_list
.
append
(
mask
)
mask_list
.
append
(
mask
)
filename
=
f
"
mask_
{
session
.
mask_names
[
idx
]
}
.tif
"
filename
=
f
"
mask_
{
session
.
mask_names
[
idx
]
}
.tif
"
base
=
os
.
path
.
join
(
session
.
gradio_temp
,
"
qim3d
"
,
session
.
username
)
if
not
os
.
path
.
exists
(
session
.
temp_dir
):
if
not
os
.
path
.
exists
(
base
):
os
.
makedirs
(
session
.
temp_dir
)
os
.
makedirs
(
base
)
filepath
=
os
.
path
.
join
(
session
.
temp_dir
,
filename
)
filepath
=
os
.
path
.
join
(
base
,
filename
)
files_list
.
append
(
filepath
)
files_list
.
append
(
filepath
)
save
(
filepath
,
mask
,
replace
=
True
)
save
(
filepath
,
mask
,
replace
=
True
)
...
...
This diff is collapsed.
Click to expand it.
qim3d/utils/internal_tools.py
+
1
−
2
View file @
a1f9598c
...
@@ -79,7 +79,7 @@ def get_local_ip():
...
@@ -79,7 +79,7 @@ def get_local_ip():
try
:
try
:
# doesn't even have to be reachable
# doesn't even have to be reachable
_socket
.
connect
((
"
192.255.255.255
"
,
1
))
_socket
.
connect
((
"
192.255.255.255
"
,
1
))
ip_address
=
_socket
.
getsockname
()
[
0
]
ip_address
=
_socket
.
getsockname
()
except
socket
.
error
:
except
socket
.
error
:
ip_address
=
"
127.0.0.1
"
ip_address
=
"
127.0.0.1
"
finally
:
finally
:
...
@@ -279,7 +279,6 @@ def run_gradio_app(gradio_interface, host = "0.0.0.0"):
...
@@ -279,7 +279,6 @@ def run_gradio_app(gradio_interface, host = "0.0.0.0"):
else
:
else
:
raise
Exception
(
"
Port not specified from QIM API
"
)
raise
Exception
(
"
Port not specified from QIM API
"
)
print
(
port_dict
)
gradio_header
(
gradio_interface
.
title
,
port
)
gradio_header
(
gradio_interface
.
title
,
port
)
# Create FastAPI with mounted gradio interface
# Create FastAPI with mounted gradio interface
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment