Upload 4 files
Browse files- app.css +8 -6
- app.py +32 -13
- cache/.gitkeep +0 -0
app.css
CHANGED
@@ -97,18 +97,20 @@
|
|
97 |
width: 80%;
|
98 |
height: 80%;
|
99 |
}
|
|
|
100 |
.show_image {
|
101 |
-
|
102 |
-
|
|
|
|
|
103 |
}
|
104 |
|
105 |
.show_image img {
|
106 |
-
width: 50
|
107 |
-
height: 50%;
|
|
|
108 |
}
|
109 |
|
110 |
-
|
111 |
-
|
112 |
.project_label {
|
113 |
font-size: 18px; /* 标题字体大小 */
|
114 |
color: #333; /* 字体颜色,这里使用深灰色 */
|
|
|
97 |
width: 80%;
|
98 |
height: 80%;
|
99 |
}
|
100 |
+
|
101 |
.show_image {
|
102 |
+
display: flex; /* 启用flexbox布局 */
|
103 |
+
justify-content: center; /* 水平居中 */
|
104 |
+
align-items: center; /* 垂直居中 */
|
105 |
+
overflow: hidden; /* 如果图像超出容器,就隐藏多余部分 */
|
106 |
}
|
107 |
|
108 |
.show_image img {
|
109 |
+
max-width: 100%; /* 图像最大宽度为容器的50%,但不超过图像原始尺寸 */
|
110 |
+
max-height: 50%; /* 图像最大高度为容器的50%,但不超过图像原始尺寸 */
|
111 |
+
height: auto; /* 高度自动调整以保持纵横比 */
|
112 |
}
|
113 |
|
|
|
|
|
114 |
.project_label {
|
115 |
font-size: 18px; /* 标题字体大小 */
|
116 |
color: #333; /* 字体颜色,这里使用深灰色 */
|
app.py
CHANGED
@@ -77,6 +77,7 @@ op_types = ['mapper', 'filter',]# 'deduplicator'] , 'selector']
|
|
77 |
local_ops_dict = {op_type:[] for op_type in op_types}
|
78 |
multimodal = os.getenv('MULTI_MODAL', True)
|
79 |
multimodal_visible = False
|
|
|
80 |
text_key = 'text'
|
81 |
image_key = 'images'
|
82 |
audio_key = 'audios'
|
@@ -125,12 +126,26 @@ def change_visible(op_name):
|
|
125 |
image_visible = True
|
126 |
return gr.update(visible=text_visible), gr.update(visible=image_visible), gr.update(visible=video_visible), gr.update(visible=audio_visible), gr.update(visible=text_visible), gr.update(visible=image_visible), gr.update(visible=video_visible), gr.update(visible=audio_visible)
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
def copy_func(file):
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
134 |
|
135 |
def encode_sample(input_text, input_image, input_video, input_audio):
|
136 |
sample = dict()
|
@@ -140,6 +155,7 @@ def encode_sample(input_text, input_image, input_video, input_audio):
|
|
140 |
sample[audio_key]=[input_audio] if input_audio else []
|
141 |
return sample
|
142 |
|
|
|
143 |
def decode_sample(output_sample):
|
144 |
output_text = output_sample[text_key]
|
145 |
output_image = output_sample[image_key][0] if output_sample[image_key] else None
|
@@ -150,6 +166,7 @@ def decode_sample(output_sample):
|
|
150 |
audio_file = copy_func(output_audio)
|
151 |
return output_text, image_file, video_file, audio_file
|
152 |
|
|
|
153 |
def create_tab_layout(op_tab, op_type, run_op, has_stats=False):
|
154 |
with op_tab:
|
155 |
options = get_op_lists(op_type)
|
@@ -167,7 +184,7 @@ def create_tab_layout(op_tab, op_type, run_op, has_stats=False):
|
|
167 |
gr.Markdown(" **Inputs**")
|
168 |
with gr.Row():
|
169 |
input_text = gr.TextArea(label="Text",interactive=True,)
|
170 |
-
input_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible
|
171 |
input_video = gr.Video(label='Video', visible=multimodal_visible)
|
172 |
input_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
173 |
|
@@ -175,7 +192,7 @@ def create_tab_layout(op_tab, op_type, run_op, has_stats=False):
|
|
175 |
gr.Markdown(" **Outputs**")
|
176 |
with gr.Row():
|
177 |
output_text = gr.TextArea(label="Text",interactive=False,)
|
178 |
-
output_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible
|
179 |
output_video = gr.Video(label='Video', visible=multimodal_visible)
|
180 |
output_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
181 |
|
@@ -215,6 +232,7 @@ def create_tab_layout(op_tab, op_type, run_op, has_stats=False):
|
|
215 |
op_selector.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4])
|
216 |
op_tab.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4])
|
217 |
|
|
|
218 |
def create_mapper_tab(op_type, op_tab):
|
219 |
with op_tab:
|
220 |
def run_op(input_text, input_image, input_video, input_audio, op_name, op_params):
|
@@ -252,6 +270,7 @@ def create_deduplicator_tab(op_type, op_tab):
|
|
252 |
return decode_sample(output_sample)
|
253 |
create_tab_layout(op_tab, op_type, run_op, has_stats=True)
|
254 |
|
|
|
255 |
def create_tab_double_layout(op_tab, op_type, run_op):
|
256 |
with op_tab:
|
257 |
options = get_op_lists(op_type)
|
@@ -270,8 +289,8 @@ def create_tab_double_layout(op_tab, op_type, run_op):
|
|
270 |
with gr.Row():
|
271 |
input_text = gr.TextArea(label="Text",interactive=True,)
|
272 |
input_text2 = gr.TextArea(label="Text",interactive=True,)
|
273 |
-
input_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible
|
274 |
-
input_image2 = gr.Image(label='Image', type='filepath', visible=multimodal_visible
|
275 |
input_video = gr.Video(label='Video', visible=multimodal_visible)
|
276 |
input_video2 = gr.Video(label='Video', visible=multimodal_visible)
|
277 |
input_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
@@ -282,8 +301,8 @@ def create_tab_double_layout(op_tab, op_type, run_op):
|
|
282 |
with gr.Row():
|
283 |
output_text = gr.TextArea(label="Text",interactive=False,)
|
284 |
output_text2 = gr.TextArea(label="Text",interactive=False,)
|
285 |
-
output_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible
|
286 |
-
output_image2 = gr.Image(label='Image', type='filepath', visible=multimodal_visible
|
287 |
output_video = gr.Video(label='Video', visible=multimodal_visible)
|
288 |
output_video2 = gr.Video(label='Video', visible=multimodal_visible)
|
289 |
output_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
@@ -316,8 +335,8 @@ def create_tab_double_layout(op_tab, op_type, run_op):
|
|
316 |
run_button.click(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4]).then(run_func, inputs=[op_selector], outputs=[code, op_params])
|
317 |
op_selector.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4]).then(show_code, inputs=[op_selector], outputs=[code, op_params])
|
318 |
op_tab.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4])
|
319 |
-
with gr.Blocks(css="./app.css") as demo:
|
320 |
|
|
|
321 |
dj_image = os.path.join(project_path, 'docs/imgs/data-juicer.jpg')
|
322 |
gr.HTML(format_cover_html(dj_image))
|
323 |
|
@@ -331,5 +350,5 @@ with gr.Blocks(css="./app.css") as demo:
|
|
331 |
create_op_tab_func(op_type, op_tab)
|
332 |
else:
|
333 |
gr.Error(f'{op_type} not callable')
|
334 |
-
|
335 |
demo.launch()
|
|
|
77 |
local_ops_dict = {op_type:[] for op_type in op_types}
|
78 |
multimodal = os.getenv('MULTI_MODAL', True)
|
79 |
multimodal_visible = False
|
80 |
+
cache_dir = './cache'
|
81 |
text_key = 'text'
|
82 |
image_key = 'images'
|
83 |
audio_key = 'audios'
|
|
|
126 |
image_visible = True
|
127 |
return gr.update(visible=text_visible), gr.update(visible=image_visible), gr.update(visible=video_visible), gr.update(visible=audio_visible), gr.update(visible=text_visible), gr.update(visible=image_visible), gr.update(visible=video_visible), gr.update(visible=audio_visible)
|
128 |
|
129 |
+
|
130 |
+
def clear_directory(directory=cache_dir):
|
131 |
+
for item in os.listdir(directory):
|
132 |
+
if item == '.gitkeep':
|
133 |
+
continue
|
134 |
+
item_path = os.path.join(directory, item)
|
135 |
+
if os.path.isfile(item_path) or os.path.islink(item_path):
|
136 |
+
os.remove(item_path) # 删除文件或链接
|
137 |
+
elif os.path.isdir(item_path):
|
138 |
+
shutil.rmtree(item_path) # 递归删除目录
|
139 |
+
|
140 |
+
|
141 |
def copy_func(file):
|
142 |
+
cache_file = None
|
143 |
+
if file:
|
144 |
+
filename= os.path.basename(file)
|
145 |
+
cache_file = os.path.join(cache_dir, filename)
|
146 |
+
shutil.copyfile(file, cache_file)
|
147 |
+
return cache_file
|
148 |
+
|
149 |
|
150 |
def encode_sample(input_text, input_image, input_video, input_audio):
|
151 |
sample = dict()
|
|
|
155 |
sample[audio_key]=[input_audio] if input_audio else []
|
156 |
return sample
|
157 |
|
158 |
+
|
159 |
def decode_sample(output_sample):
|
160 |
output_text = output_sample[text_key]
|
161 |
output_image = output_sample[image_key][0] if output_sample[image_key] else None
|
|
|
166 |
audio_file = copy_func(output_audio)
|
167 |
return output_text, image_file, video_file, audio_file
|
168 |
|
169 |
+
|
170 |
def create_tab_layout(op_tab, op_type, run_op, has_stats=False):
|
171 |
with op_tab:
|
172 |
options = get_op_lists(op_type)
|
|
|
184 |
gr.Markdown(" **Inputs**")
|
185 |
with gr.Row():
|
186 |
input_text = gr.TextArea(label="Text",interactive=True,)
|
187 |
+
input_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible)
|
188 |
input_video = gr.Video(label='Video', visible=multimodal_visible)
|
189 |
input_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
190 |
|
|
|
192 |
gr.Markdown(" **Outputs**")
|
193 |
with gr.Row():
|
194 |
output_text = gr.TextArea(label="Text",interactive=False,)
|
195 |
+
output_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible)
|
196 |
output_video = gr.Video(label='Video', visible=multimodal_visible)
|
197 |
output_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
198 |
|
|
|
232 |
op_selector.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4])
|
233 |
op_tab.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4])
|
234 |
|
235 |
+
|
236 |
def create_mapper_tab(op_type, op_tab):
|
237 |
with op_tab:
|
238 |
def run_op(input_text, input_image, input_video, input_audio, op_name, op_params):
|
|
|
270 |
return decode_sample(output_sample)
|
271 |
create_tab_layout(op_tab, op_type, run_op, has_stats=True)
|
272 |
|
273 |
+
|
274 |
def create_tab_double_layout(op_tab, op_type, run_op):
|
275 |
with op_tab:
|
276 |
options = get_op_lists(op_type)
|
|
|
289 |
with gr.Row():
|
290 |
input_text = gr.TextArea(label="Text",interactive=True,)
|
291 |
input_text2 = gr.TextArea(label="Text",interactive=True,)
|
292 |
+
input_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible)
|
293 |
+
input_image2 = gr.Image(label='Image', type='filepath', visible=multimodal_visible)
|
294 |
input_video = gr.Video(label='Video', visible=multimodal_visible)
|
295 |
input_video2 = gr.Video(label='Video', visible=multimodal_visible)
|
296 |
input_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
|
|
301 |
with gr.Row():
|
302 |
output_text = gr.TextArea(label="Text",interactive=False,)
|
303 |
output_text2 = gr.TextArea(label="Text",interactive=False,)
|
304 |
+
output_image = gr.Image(label='Image', type='filepath', visible=multimodal_visible)
|
305 |
+
output_image2 = gr.Image(label='Image', type='filepath', visible=multimodal_visible)
|
306 |
output_video = gr.Video(label='Video', visible=multimodal_visible)
|
307 |
output_video2 = gr.Video(label='Video', visible=multimodal_visible)
|
308 |
output_audio = gr.Audio(label='Audio', type='filepath', visible=multimodal_visible)
|
|
|
335 |
run_button.click(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4]).then(run_func, inputs=[op_selector], outputs=[code, op_params])
|
336 |
op_selector.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4]).then(show_code, inputs=[op_selector], outputs=[code, op_params])
|
337 |
op_tab.select(change_visible, inputs=[op_selector], outputs=outputs[:4] + inputs[:4])
|
|
|
338 |
|
339 |
+
with gr.Blocks(css="./app.css") as demo:
|
340 |
dj_image = os.path.join(project_path, 'docs/imgs/data-juicer.jpg')
|
341 |
gr.HTML(format_cover_html(dj_image))
|
342 |
|
|
|
350 |
create_op_tab_func(op_type, op_tab)
|
351 |
else:
|
352 |
gr.Error(f'{op_type} not callable')
|
353 |
+
demo.load(clear_directory, every=10)
|
354 |
demo.launch()
|
cache/.gitkeep
ADDED
File without changes
|