ksort commited on
Commit
243f5a6
1 Parent(s): 0e99a0b

Update server

Browse files
Files changed (6) hide show
  1. .gitignore +2 -1
  2. serve/Ksort.py +99 -31
  3. serve/button.css +24 -0
  4. serve/gradio_web.py +18 -18
  5. serve/upload.py +48 -23
  6. serve/utils.py +34 -2
.gitignore CHANGED
@@ -167,4 +167,5 @@ cython_debug/
167
  /*.jpg
168
  /*.ipynb
169
 
170
- GenAI-Arena-hf-logs/vote_log/*
 
 
167
  /*.jpg
168
  /*.ipynb
169
 
170
+ GenAI-Arena-hf-logs/vote_log/*
171
+ ksort-logs/
serve/Ksort.py CHANGED
@@ -1,10 +1,10 @@
1
  import gradio as gr
2
- from PIL import Image, ImageDraw, ImageFont
3
  import os
4
  from .constants import KSORT_IMAGE_DIR
5
  from .vote_utils import save_any_image
6
  from .utils import disable_btn, enable_btn, invisible_btn
7
- from .upload import create_remote_directory, upload_image, upload_informance
8
  import json
9
 
10
  def reset_level(Top_btn):
@@ -149,14 +149,15 @@ def vote_submit(states, rank, request: gr.Request):
149
  def vote_ssh_submit(states, rank):
150
  conv_id = states[0].conv_id
151
  output_dir = create_remote_directory(conv_id)
152
- upload_image(states, output_dir)
153
 
154
  data = {
155
  "models_name": [x.model_name for x in states],
156
  "img_rank": [x for x in rank],
157
  }
158
  output_file = os.path.join(output_dir, "informance.json")
159
- upload_informance(data, output_file)
 
160
 
161
  from .update_skill import update_skill
162
  update_skill(rank)
@@ -217,32 +218,62 @@ def text_response_rank_igm(generate_ig0, generate_ig1, generate_ig2, generate_ig
217
  if rank_list[num] in ['1', '2', '3', '4']:
218
  base_image = Image.fromarray(generate_ig[num]).convert("RGBA")
219
  if rank_list[num] == '1':
220
- txt_layer = Image.new('RGBA', base_image.size, (0, 255, 0, 64))
221
  elif rank_list[num] == '2':
222
- txt_layer = Image.new('RGBA', base_image.size, (0, 255, 255, 64))
223
  elif rank_list[num] == '3':
224
- txt_layer = Image.new('RGBA', base_image.size, (255, 0, 255, 64))
225
  elif rank_list[num] == '4':
226
- txt_layer = Image.new('RGBA', base_image.size, (255, 0, 0, 64))
227
- draw = ImageDraw.Draw(txt_layer)
 
 
 
228
  font = ImageFont.truetype("./serve/Arial.ttf", 86)
229
- text_position = (156, 212)
230
  if rank_list[num] == '1':
231
- text_color = (0, 255, 0, 200)
232
  draw.text(text_position, Top1_text, font=font, fill=text_color)
233
  elif rank_list[num] == '2':
234
- text_color = (0, 255, 255, 200)
235
  draw.text(text_position, Top2_text, font=font, fill=text_color)
236
  elif rank_list[num] == '3':
237
- text_color = (255, 0, 255, 200)
238
  draw.text(text_position, Top3_text, font=font, fill=text_color)
239
  elif rank_list[num] == '4':
240
- text_color = (255, 0, 0, 200)
241
  draw.text(text_position, Top4_text, font=font, fill=text_color)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
243
- combined = Image.alpha_composite(base_image, txt_layer)
244
- combined = combined.convert("RGB")
245
- chatbot.append(combined.copy())
246
  else:
247
  return generate_ig + ["error rank"] + ["wrong"] + [rank]
248
  rank_str = ""
@@ -253,35 +284,72 @@ def text_response_rank_igm(generate_ig0, generate_ig1, generate_ig2, generate_ig
253
 
254
  return chatbot + [rank_str] + ["right"] + [rank]
255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  def add_foreground(image, vote_level, Top1_text, Top2_text, Top3_text, Top4_text):
257
  base_image = Image.fromarray(image).convert("RGBA")
258
  if vote_level == 0:
259
- txt_layer = Image.new('RGBA', base_image.size, (0, 255, 0, 64))
260
  elif vote_level == 1:
261
- txt_layer = Image.new('RGBA', base_image.size, (0, 255, 255, 64))
262
  elif vote_level == 2:
263
- txt_layer = Image.new('RGBA', base_image.size, (255, 0, 255, 64))
264
  elif vote_level == 3:
265
- txt_layer = Image.new('RGBA', base_image.size, (255, 0, 0, 64))
 
 
266
 
267
- draw = ImageDraw.Draw(txt_layer)
268
  font = ImageFont.truetype("./serve/Arial.ttf", 86)
269
 
270
- text_position = (156, 212)
271
  if vote_level == 0:
272
- text_color = (0, 255, 0, 200)
273
  draw.text(text_position, Top1_text, font=font, fill=text_color)
274
  elif vote_level == 1:
275
- text_color = (0, 255, 255, 200)
276
  draw.text(text_position, Top2_text, font=font, fill=text_color)
277
  elif vote_level == 2:
278
- text_color = (255, 0, 255, 200)
279
  draw.text(text_position, Top3_text, font=font, fill=text_color)
280
  elif vote_level == 3:
281
- text_color = (255, 0, 0, 200)
282
  draw.text(text_position, Top4_text, font=font, fill=text_color)
283
 
284
- combined = Image.alpha_composite(base_image, txt_layer)
285
- combined = combined.convert("RGB")
286
- return combined
287
-
 
 
 
 
 
1
  import gradio as gr
2
+ from PIL import Image, ImageDraw, ImageFont, ImageOps
3
  import os
4
  from .constants import KSORT_IMAGE_DIR
5
  from .vote_utils import save_any_image
6
  from .utils import disable_btn, enable_btn, invisible_btn
7
+ from .upload import create_remote_directory, upload_image, upload_informance, upload_ssh_all
8
  import json
9
 
10
  def reset_level(Top_btn):
 
149
  def vote_ssh_submit(states, rank):
150
  conv_id = states[0].conv_id
151
  output_dir = create_remote_directory(conv_id)
152
+ # upload_image(states, output_dir)
153
 
154
  data = {
155
  "models_name": [x.model_name for x in states],
156
  "img_rank": [x for x in rank],
157
  }
158
  output_file = os.path.join(output_dir, "informance.json")
159
+ # upload_informance(data, output_file)
160
+ upload_ssh_all(states, output_dir, data, output_file)
161
 
162
  from .update_skill import update_skill
163
  update_skill(rank)
 
218
  if rank_list[num] in ['1', '2', '3', '4']:
219
  base_image = Image.fromarray(generate_ig[num]).convert("RGBA")
220
  if rank_list[num] == '1':
221
+ border_color = (49, 139, 190)
222
  elif rank_list[num] == '2':
223
+ border_color = (109, 116, 187)
224
  elif rank_list[num] == '3':
225
+ border_color = (159, 84, 152)
226
  elif rank_list[num] == '4':
227
+ border_color = (174, 68, 125)
228
+ border_size = 10 # Size of the border
229
+ base_image = ImageOps.expand(base_image, border=border_size, fill=border_color)
230
+
231
+ draw = ImageDraw.Draw(base_image)
232
  font = ImageFont.truetype("./serve/Arial.ttf", 86)
233
+ text_position = (300, 50)
234
  if rank_list[num] == '1':
235
+ text_color = (49, 139, 190, 255)
236
  draw.text(text_position, Top1_text, font=font, fill=text_color)
237
  elif rank_list[num] == '2':
238
+ text_color = (109, 116, 187, 255)
239
  draw.text(text_position, Top2_text, font=font, fill=text_color)
240
  elif rank_list[num] == '3':
241
+ text_color = (159, 84, 152, 255)
242
  draw.text(text_position, Top3_text, font=font, fill=text_color)
243
  elif rank_list[num] == '4':
244
+ text_color = (174, 68, 125, 255)
245
  draw.text(text_position, Top4_text, font=font, fill=text_color)
246
+ base_image = base_image.convert("RGB")
247
+ chatbot.append(base_image.copy())
248
+
249
+ # base_image = Image.fromarray(generate_ig[num]).convert("RGBA")
250
+ # if rank_list[num] == '1':
251
+ # txt_layer = Image.new('RGBA', base_image.size, (0, 255, 0, 64))
252
+ # elif rank_list[num] == '2':
253
+ # txt_layer = Image.new('RGBA', base_image.size, (0, 255, 255, 64))
254
+ # elif rank_list[num] == '3':
255
+ # txt_layer = Image.new('RGBA', base_image.size, (255, 0, 255, 64))
256
+ # elif rank_list[num] == '4':
257
+ # txt_layer = Image.new('RGBA', base_image.size, (255, 0, 0, 64))
258
+ # draw = ImageDraw.Draw(txt_layer)
259
+ # font = ImageFont.truetype("./serve/Arial.ttf", 86)
260
+ # text_position = (156, 212)
261
+ # if rank_list[num] == '1':
262
+ # text_color = (0, 255, 0, 200)
263
+ # draw.text(text_position, Top1_text, font=font, fill=text_color)
264
+ # elif rank_list[num] == '2':
265
+ # text_color = (0, 255, 255, 200)
266
+ # draw.text(text_position, Top2_text, font=font, fill=text_color)
267
+ # elif rank_list[num] == '3':
268
+ # text_color = (255, 0, 255, 200)
269
+ # draw.text(text_position, Top3_text, font=font, fill=text_color)
270
+ # elif rank_list[num] == '4':
271
+ # text_color = (255, 0, 0, 200)
272
+ # draw.text(text_position, Top4_text, font=font, fill=text_color)
273
 
274
+ # combined = Image.alpha_composite(base_image, txt_layer)
275
+ # combined = combined.convert("RGB")
276
+ # chatbot.append(combined.copy())
277
  else:
278
  return generate_ig + ["error rank"] + ["wrong"] + [rank]
279
  rank_str = ""
 
284
 
285
  return chatbot + [rank_str] + ["right"] + [rank]
286
 
287
+ # def add_foreground(image, vote_level, Top1_text, Top2_text, Top3_text, Top4_text):
288
+ # base_image = Image.fromarray(image).convert("RGBA")
289
+ # if vote_level == 0:
290
+ # txt_layer = Image.new('RGBA', base_image.size, (0, 255, 0, 64))
291
+ # elif vote_level == 1:
292
+ # txt_layer = Image.new('RGBA', base_image.size, (0, 255, 255, 64))
293
+ # elif vote_level == 2:
294
+ # txt_layer = Image.new('RGBA', base_image.size, (255, 0, 255, 64))
295
+ # elif vote_level == 3:
296
+ # txt_layer = Image.new('RGBA', base_image.size, (255, 0, 0, 64))
297
+
298
+ # draw = ImageDraw.Draw(txt_layer)
299
+ # font = ImageFont.truetype("./serve/Arial.ttf", 86)
300
+
301
+ # text_position = (156, 212)
302
+ # if vote_level == 0:
303
+ # text_color = (0, 255, 0, 200)
304
+ # draw.text(text_position, Top1_text, font=font, fill=text_color)
305
+ # elif vote_level == 1:
306
+ # text_color = (0, 255, 255, 200)
307
+ # draw.text(text_position, Top2_text, font=font, fill=text_color)
308
+ # elif vote_level == 2:
309
+ # text_color = (255, 0, 255, 200)
310
+ # draw.text(text_position, Top3_text, font=font, fill=text_color)
311
+ # elif vote_level == 3:
312
+ # text_color = (255, 0, 0, 200)
313
+ # draw.text(text_position, Top4_text, font=font, fill=text_color)
314
+
315
+ # combined = Image.alpha_composite(base_image, txt_layer)
316
+ # combined = combined.convert("RGB")
317
+ # return combined
318
  def add_foreground(image, vote_level, Top1_text, Top2_text, Top3_text, Top4_text):
319
  base_image = Image.fromarray(image).convert("RGBA")
320
  if vote_level == 0:
321
+ border_color = (49, 139, 190)
322
  elif vote_level == 1:
323
+ border_color = (109, 116, 187)
324
  elif vote_level == 2:
325
+ border_color = (159, 84, 152)
326
  elif vote_level == 3:
327
+ border_color = (174, 68, 125)
328
+ border_size = 10 # Size of the border
329
+ base_image = ImageOps.expand(base_image, border=border_size, fill=border_color)
330
 
331
+ draw = ImageDraw.Draw(base_image)
332
  font = ImageFont.truetype("./serve/Arial.ttf", 86)
333
 
334
+ text_position = (300, 50)
335
  if vote_level == 0:
336
+ text_color = (49, 139, 190, 255)
337
  draw.text(text_position, Top1_text, font=font, fill=text_color)
338
  elif vote_level == 1:
339
+ text_color = (109, 116, 187, 255)
340
  draw.text(text_position, Top2_text, font=font, fill=text_color)
341
  elif vote_level == 2:
342
+ text_color = (159, 84, 152, 255)
343
  draw.text(text_position, Top3_text, font=font, fill=text_color)
344
  elif vote_level == 3:
345
+ text_color = (174, 68, 125, 255)
346
  draw.text(text_position, Top4_text, font=font, fill=text_color)
347
 
348
+ # combined = Image.alpha_composite(base_image, txt_layer)
349
+ base_image = base_image.convert("RGB")
350
+ return base_image
351
+ def add_green_border(image):
352
+ border_color = (0, 255, 0) # RGB for green
353
+ border_size = 10 # Size of the border
354
+ img_with_border = ImageOps.expand(image, border=border_size, fill=border_color)
355
+ return img_with_border
serve/button.css ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* style.css */
2
+ .custom-button {
3
+ background-color: greenyellow; /* 背景颜色 */
4
+ color: white; /* 文字颜色 */
5
+ border: none; /* 无边框 */
6
+ padding: 10px 20px; /* 内边距 */
7
+ text-align: center; /* 文本居中 */
8
+ text-decoration: none; /* 无下划线 */
9
+ display: inline-block; /* 行内块 */
10
+ font-size: 16px; /* 字体大小 */
11
+ margin: 4px 2px; /* 外边距 */
12
+ cursor: pointer; /* 鼠标指针 */
13
+ border-radius: 5px; /* 圆角边框 */
14
+ }
15
+
16
+ .custom-button:hover {
17
+ background-color: darkgreen; /* 悬停时的背景颜色 */
18
+ }
19
+ /* css = """
20
+ #warning {background: red;}
21
+
22
+ .feedback {font-size: 24px !important;}
23
+ .feedback textarea {font-size: 24px !important;}
24
+ """ */
serve/gradio_web.py CHANGED
@@ -33,7 +33,7 @@ from .Ksort import (
33
  text_response_rank_igm,
34
  )
35
  from functools import partial
36
-
37
  def build_side_by_side_ui_anony(models):
38
  notice_markdown = """
39
  # ⚔️ Text2Image-Arena ⚔️
@@ -124,77 +124,77 @@ Find out who is the 🥇conditional image generation models! More models are goi
124
  )
125
  Submit_btn = gr.Button(value="🤝 Submit", visible=False, interactive=False)
126
  with gr.Row():
127
- with gr.Blocks():
128
  with gr.Row():
129
  with gr.Column(scale=1, min_width=10):
130
  A1_btn = gr.Button(
131
- value="1", visible=False, interactive=False
132
  )
133
  with gr.Column(scale=1, min_width=10):
134
  A2_btn = gr.Button(
135
- value="2", visible=False, interactive=False
136
  )
137
  with gr.Column(scale=1, min_width=10):
138
  A3_btn = gr.Button(
139
- value="3", visible=False, interactive=False
140
  )
141
  with gr.Column(scale=1, min_width=10):
142
  A4_btn = gr.Button(
143
- value="4", visible=False, interactive=False
144
  )
145
  with gr.Blocks():
146
  with gr.Row():
147
  with gr.Column(scale=1, min_width=10):
148
  B1_btn = gr.Button(
149
- value="1", visible=False, interactive=False
150
  )
151
  with gr.Column(scale=1, min_width=10):
152
  B2_btn = gr.Button(
153
- value="2", visible=False, interactive=False
154
  )
155
  with gr.Column(scale=1, min_width=10):
156
  B3_btn = gr.Button(
157
- value="3", visible=False, interactive=False
158
  )
159
  with gr.Column(scale=1, min_width=10):
160
  B4_btn = gr.Button(
161
- value="4", visible=False, interactive=False
162
  )
163
  with gr.Blocks():
164
  with gr.Row():
165
  with gr.Column(scale=1, min_width=10):
166
  C1_btn = gr.Button(
167
- value="1", visible=False, interactive=False
168
  )
169
  with gr.Column(scale=1, min_width=10):
170
  C2_btn = gr.Button(
171
- value="2", visible=False, interactive=False
172
  )
173
  with gr.Column(scale=1, min_width=10):
174
  C3_btn = gr.Button(
175
- value="3", visible=False, interactive=False
176
  )
177
  with gr.Column(scale=1, min_width=10):
178
  C4_btn = gr.Button(
179
- value="4", visible=False, interactive=False
180
  )
181
  with gr.Blocks():
182
  with gr.Row():
183
  with gr.Column(scale=1, min_width=10):
184
  D1_btn = gr.Button(
185
- value="1", visible=False, interactive=False
186
  )
187
  with gr.Column(scale=1, min_width=10):
188
  D2_btn = gr.Button(
189
- value="2", visible=False, interactive=False
190
  )
191
  with gr.Column(scale=1, min_width=10):
192
  D3_btn = gr.Button(
193
- value="3", visible=False, interactive=False
194
  )
195
  with gr.Column(scale=1, min_width=10):
196
  D4_btn = gr.Button(
197
- value="4", visible=False, interactive=False
198
  )
199
 
200
  with gr.Row():
 
33
  text_response_rank_igm,
34
  )
35
  from functools import partial
36
+
37
  def build_side_by_side_ui_anony(models):
38
  notice_markdown = """
39
  # ⚔️ Text2Image-Arena ⚔️
 
124
  )
125
  Submit_btn = gr.Button(value="🤝 Submit", visible=False, interactive=False)
126
  with gr.Row():
127
+ with gr.Blocks():
128
  with gr.Row():
129
  with gr.Column(scale=1, min_width=10):
130
  A1_btn = gr.Button(
131
+ value="1", visible=False, interactive=False, elem_id="btncolor1", elem_classes="custom-button"
132
  )
133
  with gr.Column(scale=1, min_width=10):
134
  A2_btn = gr.Button(
135
+ value="2", visible=False, interactive=False, elem_id="btncolor2", elem_classes="custom-button"
136
  )
137
  with gr.Column(scale=1, min_width=10):
138
  A3_btn = gr.Button(
139
+ value="3", visible=False, interactive=False, elem_id="btncolor3", elem_classes="custom-button"
140
  )
141
  with gr.Column(scale=1, min_width=10):
142
  A4_btn = gr.Button(
143
+ value="4", visible=False, interactive=False, elem_id="btncolor4", elem_classes="custom-button"
144
  )
145
  with gr.Blocks():
146
  with gr.Row():
147
  with gr.Column(scale=1, min_width=10):
148
  B1_btn = gr.Button(
149
+ value="1", visible=False, interactive=False, elem_id="btncolor1", elem_classes="custom-button"
150
  )
151
  with gr.Column(scale=1, min_width=10):
152
  B2_btn = gr.Button(
153
+ value="2", visible=False, interactive=False, elem_id="btncolor2", elem_classes="custom-button"
154
  )
155
  with gr.Column(scale=1, min_width=10):
156
  B3_btn = gr.Button(
157
+ value="3", visible=False, interactive=False, elem_id="btncolor3", elem_classes="custom-button"
158
  )
159
  with gr.Column(scale=1, min_width=10):
160
  B4_btn = gr.Button(
161
+ value="4", visible=False, interactive=False, elem_id="btncolor4", elem_classes="custom-button"
162
  )
163
  with gr.Blocks():
164
  with gr.Row():
165
  with gr.Column(scale=1, min_width=10):
166
  C1_btn = gr.Button(
167
+ value="1", visible=False, interactive=False, elem_id="btncolor1", elem_classes="custom-button"
168
  )
169
  with gr.Column(scale=1, min_width=10):
170
  C2_btn = gr.Button(
171
+ value="2", visible=False, interactive=False, elem_id="btncolor2", elem_classes="custom-button"
172
  )
173
  with gr.Column(scale=1, min_width=10):
174
  C3_btn = gr.Button(
175
+ value="3", visible=False, interactive=False, elem_id="btncolor3", elem_classes="custom-button"
176
  )
177
  with gr.Column(scale=1, min_width=10):
178
  C4_btn = gr.Button(
179
+ value="4", visible=False, interactive=False, elem_id="btncolor4", elem_classes="custom-button"
180
  )
181
  with gr.Blocks():
182
  with gr.Row():
183
  with gr.Column(scale=1, min_width=10):
184
  D1_btn = gr.Button(
185
+ value="1", visible=False, interactive=False, elem_id="btncolor1", elem_classes="custom-button"
186
  )
187
  with gr.Column(scale=1, min_width=10):
188
  D2_btn = gr.Button(
189
+ value="2", visible=False, interactive=False, elem_id="btncolor2", elem_classes="custom-button"
190
  )
191
  with gr.Column(scale=1, min_width=10):
192
  D3_btn = gr.Button(
193
+ value="3", visible=False, interactive=False, elem_id="btncolor3", elem_classes="custom-button"
194
  )
195
  with gr.Column(scale=1, min_width=10):
196
  D4_btn = gr.Button(
197
+ value="4", visible=False, interactive=False, elem_id="btncolor4", elem_classes="custom-button"
198
  )
199
 
200
  with gr.Row():
serve/upload.py CHANGED
@@ -18,33 +18,35 @@ def get_image_from_url(image_url):
18
  response.raise_for_status() # success
19
  return Image.open(io.BytesIO(response.content))
20
 
21
- def upload_image_via_sftp(ssh, image, remote_image_path):
22
- if isinstance(image, str):
23
- print("get url image")
24
- image = get_image_from_url(image)
25
- with ssh.open_sftp() as sftp:
26
- with io.BytesIO() as image_byte_stream:
27
- image.save(image_byte_stream, format='JPEG')
28
- image_byte_stream.seek(0)
29
- sftp.putfo(image_byte_stream, remote_image_path)
30
- print(f"Successfully uploaded image to {remote_image_path}")
31
 
32
- def upload_json_via_sftp(ssh, data, remote_json_path):
33
- json_data = json.dumps(data, indent=4)
34
- with ssh.open_sftp() as sftp:
35
- with io.BytesIO(json_data.encode('utf-8')) as json_byte_stream:
36
- sftp.putfo(json_byte_stream, remote_json_path)
37
- print(f"Successfully uploaded JSON data to {remote_json_path}")
38
 
39
  def upload_image(states, output_dir):
40
- ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
41
- for i in range(len(states)):
42
- output_file = os.path.join(output_dir, f"{i}.jpg")
43
- upload_image_via_sftp(ssh, states[i].output, output_file)
 
44
 
45
  def upload_informance(data, data_path):
46
- ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
47
- upload_json_via_sftp(ssh, data, data_path)
 
48
 
49
  def create_remote_directory(remote_directory):
50
  ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
@@ -57,4 +59,27 @@ def create_remote_directory(remote_directory):
57
  print(f"Directory {remote_directory} created successfully.")
58
  # ssh.close()
59
  return f'{SSH_LOG}/{remote_directory}'
60
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  response.raise_for_status() # success
19
  return Image.open(io.BytesIO(response.content))
20
 
21
+ # def upload_image_via_sftp(ssh, image, remote_image_path):
22
+ # if isinstance(image, str):
23
+ # print("get url image")
24
+ # image = get_image_from_url(image)
25
+ # with ssh.open_sftp() as sftp:
26
+ # with io.BytesIO() as image_byte_stream:
27
+ # image.save(image_byte_stream, format='JPEG')
28
+ # image_byte_stream.seek(0)
29
+ # sftp.putfo(image_byte_stream, remote_image_path)
30
+ # print(f"Successfully uploaded image to {remote_image_path}")
31
 
32
+ # def upload_json_via_sftp(ssh, data, remote_json_path):
33
+ # json_data = json.dumps(data, indent=4)
34
+ # with ssh.open_sftp() as sftp:
35
+ # with io.BytesIO(json_data.encode('utf-8')) as json_byte_stream:
36
+ # sftp.putfo(json_byte_stream, remote_json_path)
37
+ # print(f"Successfully uploaded JSON data to {remote_json_path}")
38
 
39
  def upload_image(states, output_dir):
40
+ pass
41
+ # ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
42
+ # for i in range(len(states)):
43
+ # output_file = os.path.join(output_dir, f"{i}.jpg")
44
+ # upload_image_via_sftp(ssh, states[i].output, output_file)
45
 
46
  def upload_informance(data, data_path):
47
+ pass
48
+ # ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
49
+ # upload_json_via_sftp(ssh, data, data_path)
50
 
51
  def create_remote_directory(remote_directory):
52
  ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
 
59
  print(f"Directory {remote_directory} created successfully.")
60
  # ssh.close()
61
  return f'{SSH_LOG}/{remote_directory}'
62
+
63
+ def upload_ssh_all(states, output_dir, data, data_path):
64
+ ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
65
+ output_file_list = []
66
+ image_list = []
67
+ for i in range(len(states)):
68
+ output_file = os.path.join(output_dir, f"{i}.jpg")
69
+ output_file_list.append(output_file)
70
+ image_list.append(states[i].output)
71
+
72
+ with ssh.open_sftp() as sftp:
73
+ for i in range(len(output_file_list)):
74
+ if isinstance(image_list[i], str):
75
+ print("get url image")
76
+ image_list[i] = get_image_from_url(image_list[i])
77
+ with io.BytesIO() as image_byte_stream:
78
+ image_list[i].save(image_byte_stream, format='JPEG')
79
+ image_byte_stream.seek(0)
80
+ sftp.putfo(image_byte_stream, output_file_list[i])
81
+ print(f"Successfully uploaded image to {output_file_list[i]}")
82
+ json_data = json.dumps(data, indent=4)
83
+ with io.BytesIO(json_data.encode('utf-8')) as json_byte_stream:
84
+ sftp.putfo(json_byte_stream, data_path)
85
+ print(f"Successfully uploaded JSON data to {data_path}")
serve/utils.py CHANGED
@@ -46,7 +46,7 @@ acknowledgment_md = """
46
  <p> Our codebase is built upon <a href="https://github.com/lm-sys/FastChat" target="_blank">FastChat</a>, <a href="https://github.com/TIGER-AI-Lab/ImagenHub" target="_blank">ImagenHub</a> and <a href="https://github.com/TIGER-AI-Lab/VideoGenHub" target="_blank">VideoGenHub</a>.</p>
47
  </div>
48
  """
49
-
50
  block_css = """
51
  #notice_markdown {
52
  font-size: 110%
@@ -96,8 +96,40 @@ footer {
96
  width: auto;
97
  max-width: 30%;}
98
  }
99
- """
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  def enable_vote_buttons():
102
  return tuple(gr.update(visible=True, interactive=i<=4) for i in range(6))
103
  def disable_vote_buttons():
 
46
  <p> Our codebase is built upon <a href="https://github.com/lm-sys/FastChat" target="_blank">FastChat</a>, <a href="https://github.com/TIGER-AI-Lab/ImagenHub" target="_blank">ImagenHub</a> and <a href="https://github.com/TIGER-AI-Lab/VideoGenHub" target="_blank">VideoGenHub</a>.</p>
47
  </div>
48
  """
49
+ color = "rgb(49, 139, 190)"
50
  block_css = """
51
  #notice_markdown {
52
  font-size: 110%
 
96
  width: auto;
97
  max-width: 30%;}
98
  }
 
99
 
100
+ .custom-button {
101
+ border-radius: 8px;
102
+ }
103
+ #btncolor1 {background: rgb(49, 139, 190);}
104
+ #btncolor2 {background: rgb(109, 116, 187);}
105
+ #btncolor3 {background: rgb(159, 84, 152);}
106
+ #btncolor4 {background: rgb(174, 68, 125);}
107
+ """
108
+ # .custom-button {
109
+ # padding: 10px 15px;
110
+ # text-align: center;
111
+ # text-decoration: none;
112
+ # display: inline-block;
113
+ # font-size: 16px;
114
+ # cursor: pointer;
115
+ # border-radius: 8px;
116
+ # }
117
+ # {
118
+ # background-color: green; /* 背景颜色 */
119
+ # color: white; /* 文字颜色 */
120
+ # border: none; /* 无边框 */
121
+ # padding: 10px 20px; /* 内边距 */
122
+ # text-align: center; /* 文本居中 */
123
+ # text-decoration: none; /* 无下划线 */
124
+ # display: inline-block; /* 行内块 */
125
+ # font-size: 16px; /* 字体大小 */
126
+ # margin: 4px 2px; /* 外边距 */
127
+ # cursor: pointer; /* 鼠标指针 */
128
+ # border-radius: 5px; /* 圆角边框 */
129
+ # }
130
+ # .custom-button:hover {
131
+ # background-color: darkgreen; /* 悬停时的背景颜色 */
132
+ # }
133
  def enable_vote_buttons():
134
  return tuple(gr.update(visible=True, interactive=i<=4) for i in range(6))
135
  def disable_vote_buttons():