Spaces:
Sleeping
Sleeping
Update my_model/utilities/gen_utilities.py
Browse files
my_model/utilities/gen_utilities.py
CHANGED
@@ -8,16 +8,51 @@ from IPython import get_ipython
|
|
8 |
import sys
|
9 |
import gc
|
10 |
import streamlit as st
|
|
|
|
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def show_image(image):
|
14 |
"""
|
15 |
Display an image in various environments (Jupyter, PyCharm, Hugging Face Spaces).
|
16 |
Handles different types of image inputs (file path, PIL Image, numpy array, OpenCV, PyTorch tensor).
|
17 |
|
18 |
Args:
|
19 |
-
|
20 |
"""
|
|
|
21 |
in_jupyter = is_jupyter_notebook()
|
22 |
in_colab = is_google_colab()
|
23 |
|
|
|
8 |
import sys
|
9 |
import gc
|
10 |
import streamlit as st
|
11 |
+
import logging
|
12 |
+
import functools
|
13 |
|
14 |
|
15 |
+
|
16 |
+
# Set up logging
|
17 |
+
logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(message)s')
|
18 |
+
|
19 |
+
def log_event(event: str) -> None:
|
20 |
+
"""
|
21 |
+
Logs an event with the current timestamp.
|
22 |
+
|
23 |
+
Args:
|
24 |
+
event (str): The event description to log.
|
25 |
+
"""
|
26 |
+
logging.info(event)
|
27 |
+
|
28 |
+
def log_function_call(func):
|
29 |
+
"""
|
30 |
+
Decorator that logs the function call details (name and arguments).
|
31 |
+
|
32 |
+
Args:
|
33 |
+
func (function): The function to be decorated.
|
34 |
+
|
35 |
+
Returns:
|
36 |
+
function: The wrapped function with logging.
|
37 |
+
"""
|
38 |
+
@functools.wraps(func)
|
39 |
+
def wrapper(*args, **kwargs):
|
40 |
+
log_event(f'Function {func.__name__} called with args: {args} and kwargs: {kwargs}')
|
41 |
+
result = func(*args, **kwargs)
|
42 |
+
log_event(f'Function {func.__name__} completed')
|
43 |
+
return result
|
44 |
+
return wrapper
|
45 |
+
|
46 |
+
|
47 |
def show_image(image):
|
48 |
"""
|
49 |
Display an image in various environments (Jupyter, PyCharm, Hugging Face Spaces).
|
50 |
Handles different types of image inputs (file path, PIL Image, numpy array, OpenCV, PyTorch tensor).
|
51 |
|
52 |
Args:
|
53 |
+
image (str or PIL.Image or numpy.ndarray or torch.Tensor): The image to display.
|
54 |
"""
|
55 |
+
|
56 |
in_jupyter = is_jupyter_notebook()
|
57 |
in_colab = is_google_colab()
|
58 |
|