Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
50b7dc1
1
Parent(s):
feb9dbd
Update app.py
Browse files
app.py
CHANGED
@@ -39,9 +39,9 @@ MAX_IMAGES = 150
|
|
39 |
|
40 |
|
41 |
def load_captioning(uploaded_images, concept_sentence):
|
42 |
-
|
43 |
uploaded_images = [file for file in uploaded_images if not file.endswith('.txt')]
|
44 |
txt_files = [file for file in uploaded_images if file.endswith('.txt')]
|
|
|
45 |
|
46 |
gr.Info("Images uploaded!")
|
47 |
updates = []
|
@@ -67,15 +67,11 @@ def load_captioning(uploaded_images, concept_sentence):
|
|
67 |
updates.append(gr.update(value=image_value, visible=visible))
|
68 |
|
69 |
corresponding_caption = False
|
70 |
-
print(txt_files)
|
71 |
if(image_value):
|
72 |
-
|
73 |
-
base_name
|
74 |
-
|
75 |
-
|
76 |
-
if corresponding_txt in txt_files:
|
77 |
-
with open(corresponding_txt, 'r') as file:
|
78 |
-
corresponding_caption = file.read()
|
79 |
# Update value of captioning area
|
80 |
text_value = corresponding_caption if visible and corresponding_caption else "[trigger]" if visible and concept_sentence else None
|
81 |
updates.append(gr.update(value=text_value, visible=visible))
|
|
|
39 |
|
40 |
|
41 |
def load_captioning(uploaded_images, concept_sentence):
|
|
|
42 |
uploaded_images = [file for file in uploaded_images if not file.endswith('.txt')]
|
43 |
txt_files = [file for file in uploaded_images if file.endswith('.txt')]
|
44 |
+
txt_files_dict = {os.path.splitext(os.path.basename(txt_file))[0]: txt_file for txt_file in txt_files}
|
45 |
|
46 |
gr.Info("Images uploaded!")
|
47 |
updates = []
|
|
|
67 |
updates.append(gr.update(value=image_value, visible=visible))
|
68 |
|
69 |
corresponding_caption = False
|
|
|
70 |
if(image_value):
|
71 |
+
base_name = os.path.splitext(os.path.basename(image))[0]
|
72 |
+
if base_name in txt_file_dict:
|
73 |
+
with open(txt_file_dict[base_name], 'r') as file:
|
74 |
+
corresponding_caption = file.read()
|
|
|
|
|
|
|
75 |
# Update value of captioning area
|
76 |
text_value = corresponding_caption if visible and corresponding_caption else "[trigger]" if visible and concept_sentence else None
|
77 |
updates.append(gr.update(value=text_value, visible=visible))
|