Spaces:
Build error
Build error
Upload 7 files
Browse files
SessionState.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from streamlit.report_thread import get_report_ctx
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
class SessionState(object):
|
| 5 |
+
def __init__(self, **kwargs):
|
| 6 |
+
"""A new SessionState object.
|
| 7 |
+
|
| 8 |
+
Parameters
|
| 9 |
+
----------
|
| 10 |
+
**kwargs : any
|
| 11 |
+
Default values for the session state.
|
| 12 |
+
|
| 13 |
+
Example
|
| 14 |
+
-------
|
| 15 |
+
>>> session_state = SessionState(user_name='', favorite_color='black')
|
| 16 |
+
>>> session_state.user_name = 'Mary'
|
| 17 |
+
''
|
| 18 |
+
>>> session_state.favorite_color
|
| 19 |
+
'black'
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
for key, val in kwargs.items():
|
| 23 |
+
setattr(self, key, val)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@st.cache(allow_output_mutation=True)
|
| 27 |
+
def get_session(id, **kwargs):
|
| 28 |
+
return SessionState(**kwargs)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def get(**kwargs):
|
| 32 |
+
"""Gets a SessionState object for the current session.
|
| 33 |
+
|
| 34 |
+
Creates a new object if necessary.
|
| 35 |
+
|
| 36 |
+
Parameters
|
| 37 |
+
----------
|
| 38 |
+
**kwargs : any
|
| 39 |
+
Default values you want to add to the session state, if we're creating a
|
| 40 |
+
new one.
|
| 41 |
+
|
| 42 |
+
Example
|
| 43 |
+
-------
|
| 44 |
+
>>> session_state = get(user_name='', favorite_color='black')
|
| 45 |
+
>>> session_state.user_name
|
| 46 |
+
''
|
| 47 |
+
>>> session_state.user_name = 'Mary'
|
| 48 |
+
>>> session_state.favorite_color
|
| 49 |
+
'black'
|
| 50 |
+
|
| 51 |
+
Since you set user_name above, next time your script runs this will be the
|
| 52 |
+
result:
|
| 53 |
+
>>> session_state = get(user_name='', favorite_color='black')
|
| 54 |
+
>>> session_state.user_name
|
| 55 |
+
'Mary'
|
| 56 |
+
|
| 57 |
+
"""
|
| 58 |
+
ctx = get_report_ctx()
|
| 59 |
+
id = ctx.session_id
|
| 60 |
+
return get_session(id, **kwargs)
|
helper_fns/__init__.py
ADDED
|
File without changes
|
helper_fns/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (236 Bytes). View file
|
|
|
helper_fns/__pycache__/__init__.cpython-39.pyc
ADDED
|
Binary file (161 Bytes). View file
|
|
|
helper_fns/__pycache__/gan_utils.cpython-312.pyc
ADDED
|
Binary file (1.74 kB). View file
|
|
|
helper_fns/__pycache__/gan_utils.cpython-39.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
helper_fns/gan_utils.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
def make_square(image, min_size=512, fill_color=(255, 255, 255, 0)):
|
| 5 |
+
'''
|
| 6 |
+
Make a square image with signature in the center and black (transparent)
|
| 7 |
+
strips on top and bottom. Cycle GAN is trained with images of this format.
|
| 8 |
+
'''
|
| 9 |
+
x, y = image.size
|
| 10 |
+
size = max(min_size, x, y)
|
| 11 |
+
new_im = Image.new('RGBA', (size, size), fill_color)
|
| 12 |
+
new_im.paste(image, (int((size - x) / 2), int((size - y) / 2)))
|
| 13 |
+
new_im = new_im.resize((512, 512))
|
| 14 |
+
return new_im
|
| 15 |
+
|
| 16 |
+
def resize_images(path):
|
| 17 |
+
'''
|
| 18 |
+
Resize all the images present in path that matches the ips used in cyclegan
|
| 19 |
+
training
|
| 20 |
+
'''
|
| 21 |
+
dirs = os.listdir(path)
|
| 22 |
+
for item in dirs:
|
| 23 |
+
if os.path.isfile(path+item):
|
| 24 |
+
image = Image.open(path+item)
|
| 25 |
+
image = make_square(image)
|
| 26 |
+
image = image.convert('RGB')
|
| 27 |
+
image.save(path+item)
|
| 28 |
+
|
| 29 |
+
# test_path = 'runs/detect/exp/crops/DLSignature/'
|
| 30 |
+
# resize_images(test_path)
|