gokaygokay
commited on
Commit
•
b5c347a
1
Parent(s):
c569a26
Update app.py
Browse files
app.py
CHANGED
@@ -16,11 +16,11 @@ TITLE = "# [Florence-2 SD3 Long Captioner](https://huggingface.co/gokaygokay/Flo
|
|
16 |
|
17 |
def modify_caption(caption: str) -> str:
|
18 |
"""
|
19 |
-
Removes specific prefixes from captions.
|
20 |
Args:
|
21 |
caption (str): A string containing a caption.
|
22 |
Returns:
|
23 |
-
str: The caption with the prefix removed if it was present.
|
24 |
"""
|
25 |
# Define the prefixes to remove
|
26 |
prefix_substrings = [
|
@@ -37,7 +37,10 @@ def modify_caption(caption: str) -> str:
|
|
37 |
return replacers[match.group(0)]
|
38 |
|
39 |
# Apply the regex to the caption
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
@spaces.GPU
|
43 |
def run_example(image):
|
|
|
16 |
|
17 |
def modify_caption(caption: str) -> str:
|
18 |
"""
|
19 |
+
Removes specific prefixes from captions if present, otherwise returns the original caption.
|
20 |
Args:
|
21 |
caption (str): A string containing a caption.
|
22 |
Returns:
|
23 |
+
str: The caption with the prefix removed if it was present, or the original caption.
|
24 |
"""
|
25 |
# Define the prefixes to remove
|
26 |
prefix_substrings = [
|
|
|
37 |
return replacers[match.group(0)]
|
38 |
|
39 |
# Apply the regex to the caption
|
40 |
+
modified_caption = re.sub(pattern, replace_fn, caption, count=1, flags=re.IGNORECASE)
|
41 |
+
|
42 |
+
# If the caption was modified, return the modified version; otherwise, return the original
|
43 |
+
return modified_caption if modified_caption != caption else caption
|
44 |
|
45 |
@spaces.GPU
|
46 |
def run_example(image):
|