Surn commited on
Commit
52881a1
·
1 Parent(s): 59dece3

Minor Update

Browse files
Files changed (3) hide show
  1. style_20250314.css +2 -2
  2. utils/color_utils.py +15 -0
  3. utils/file_utils.py +27 -1
style_20250314.css CHANGED
@@ -18,11 +18,11 @@
18
  font-size: 1.2em !important;
19
  font-weight: bold;
20
  text-align: center;
21
- background-color: rgba(242, 218, 163, 0.62);
22
  }
23
 
24
  .dark .gradio-container.gradio-container-5-23-3 .contain .intro .prose {
25
- background-color: rgba(41, 18, 5, 0.38) !important;
26
  }
27
  .toast-body.info {
28
  background-color: rgba(242, 218, 163, 0.75);
 
18
  font-size: 1.2em !important;
19
  font-weight: bold;
20
  text-align: center;
21
+ /*background-color: rgba(242, 218, 163, 0.62);*/
22
  }
23
 
24
  .dark .gradio-container.gradio-container-5-23-3 .contain .intro .prose {
25
+ /*background-color: rgba(41, 18, 5, 0.38) !important;*/
26
  }
27
  .toast-body.info {
28
  background-color: rgba(242, 218, 163, 0.75);
utils/color_utils.py CHANGED
@@ -135,6 +135,21 @@ def detect_color_format(color):
135
  # If none of the above conversions work, raise an error
136
  raise ValueError(f"Invalid color format: {color}")
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  def update_color_opacity(color, opacity):
140
  """
 
135
  # If none of the above conversions work, raise an error
136
  raise ValueError(f"Invalid color format: {color}")
137
 
138
+ def rgba_to_tuple(rgba):
139
+ """
140
+ Converts an RGBA color in the format RGBA(r, g, b, a) to a tuple (r, g, b, a).
141
+
142
+ Args:
143
+ rgba (str): The RGBA color string in the format RGBA(r, g, b, a).
144
+
145
+ Returns:
146
+ tuple: A tuple (r, g, b, a) with int values.
147
+ """
148
+ match = re.match(r'rgba\(\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+)\s*\)', rgba, re.IGNORECASE)
149
+ if match:
150
+ rgba_floats = tuple(map(float, match.groups()))
151
+ return tuple(map(int,rgba_floats))
152
+ raise ValueError(f"Invalid RGBA format: {rgba}")
153
 
154
  def update_color_opacity(color, opacity):
155
  """
utils/file_utils.py CHANGED
@@ -77,4 +77,30 @@ def convert_title_to_filename(title):
77
  def get_filename_from_filepath(filepath):
78
  file_name = os.path.basename(filepath)
79
  file_base, file_extension = os.path.splitext(file_name)
80
- return file_base, file_extension
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  def get_filename_from_filepath(filepath):
78
  file_name = os.path.basename(filepath)
79
  file_base, file_extension = os.path.splitext(file_name)
80
+ return file_base, file_extension
81
+
82
+ def get_unique_file_path(directory, filename, file_ext, counter=0):
83
+ """
84
+ Recursively increments the filename until a unique path is found.
85
+
86
+ Parameters:
87
+ directory (str): The directory for the file.
88
+ filename (str): The base filename.
89
+ file_ext (str): The file extension including the leading dot.
90
+ counter (int): The current counter value to append.
91
+
92
+ Returns:
93
+ str: A unique file path that does not exist.
94
+ """
95
+ if counter == 0:
96
+ filepath = os.path.join(directory, f"{filename}{file_ext}")
97
+ else:
98
+ filepath = os.path.join(directory, f"{filename}{counter}{file_ext}")
99
+
100
+ if not os.path.exists(filepath):
101
+ return filepath
102
+ else:
103
+ return get_unique_file_path(directory, filename, file_ext, counter + 1)
104
+
105
+ # Example usage:
106
+ # new_file_path = get_unique_file_path(video_dir, title_file_name, video_new_ext)