DongfuJiang commited on
Commit
d994c39
1 Parent(s): a724d8a
Files changed (2) hide show
  1. serve/utils.py +5 -0
  2. serve/vote_utils.py +24 -24
serve/utils.py CHANGED
@@ -143,6 +143,11 @@ def get_conv_log_filename():
143
  name = os.path.join(LOGDIR, f"{t.year}-{t.month:02d}-{t.day:02d}-conv.json")
144
  return name
145
 
 
 
 
 
 
146
  def save_image_file_on_log_server(image_file:str):
147
 
148
  image_file = Path(image_file).absolute().relative_to(os.getcwd())
 
143
  name = os.path.join(LOGDIR, f"{t.year}-{t.month:02d}-{t.day:02d}-conv.json")
144
  return name
145
 
146
+ def get_nsfw_conv_log_filename():
147
+ t = datetime.datetime.now()
148
+ name = os.path.join(LOGDIR, f"nsfw/{t.year}-{t.month:02d}-{t.day:02d}-conv.json")
149
+ return name
150
+
151
  def save_image_file_on_log_server(image_file:str):
152
 
153
  image_file = Path(image_file).absolute().relative_to(os.getcwd())
serve/vote_utils.py CHANGED
@@ -518,7 +518,7 @@ def generate_ig(gen_func, state, text, model_name, request: gr.Request):
518
  state.output = generated_image
519
  state.model_name = model_name
520
  if generated_image == '':
521
- with open(get_conv_log_filename(), "a") as fout:
522
  data = {
523
  "type": "chat",
524
  "model": model_name,
@@ -528,7 +528,7 @@ def generate_ig(gen_func, state, text, model_name, request: gr.Request):
528
  "ip": get_ip(request),
529
  }
530
  fout.write(json.dumps(data) + "\n")
531
- append_json_item_on_log_server(data, get_conv_log_filename())
532
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
533
 
534
  yield state, generated_image
@@ -616,7 +616,7 @@ def generate_igm(gen_func, state0, state1, text, model_name0, model_name1, reque
616
  state0.model_name = model_name0
617
  state1.model_name = model_name1
618
  if generated_image0 == '' and generated_image1 == '':
619
- with open(get_conv_log_filename(), "a") as fout:
620
  data = {
621
  "type": "chat",
622
  "model": model_name0,
@@ -626,7 +626,7 @@ def generate_igm(gen_func, state0, state1, text, model_name0, model_name1, reque
626
  "ip": get_ip(request),
627
  }
628
  fout.write(json.dumps(data) + "\n")
629
- append_json_item_on_log_server(data, get_conv_log_filename())
630
  data = {
631
  "type": "chat",
632
  "model": model_name1,
@@ -636,7 +636,7 @@ def generate_igm(gen_func, state0, state1, text, model_name0, model_name1, reque
636
  "ip": get_ip(request),
637
  }
638
  fout.write(json.dumps(data) + "\n")
639
- append_json_item_on_log_server(data, get_conv_log_filename())
640
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
641
 
642
  yield state0, state1, generated_image0, generated_image1
@@ -755,7 +755,7 @@ def generate_igm_annoy(gen_func, state0, state1, text, model_name0, model_name1,
755
  state0.model_name = model_name0
756
  state1.model_name = model_name1
757
  if generated_image0 == '' and generated_image1 == '':
758
- with open(get_conv_log_filename(), "a") as fout:
759
  data = {
760
  "type": "chat",
761
  "model": model_name0,
@@ -765,7 +765,7 @@ def generate_igm_annoy(gen_func, state0, state1, text, model_name0, model_name1,
765
  "ip": get_ip(request),
766
  }
767
  fout.write(json.dumps(data) + "\n")
768
- append_json_item_on_log_server(data, get_conv_log_filename())
769
  data = {
770
  "type": "chat",
771
  "model": model_name1,
@@ -775,7 +775,7 @@ def generate_igm_annoy(gen_func, state0, state1, text, model_name0, model_name1,
775
  "ip": get_ip(request),
776
  }
777
  fout.write(json.dumps(data) + "\n")
778
- append_json_item_on_log_server(data, get_conv_log_filename())
779
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
780
 
781
 
@@ -899,7 +899,7 @@ def generate_ie(gen_func, state, source_text, target_text, instruct_text, source
899
  state.model_name = model_name
900
 
901
  if generated_image == '':
902
- with open(get_conv_log_filename(), "a") as fout:
903
  data = {
904
  "type": "chat",
905
  "model": model_name,
@@ -909,7 +909,7 @@ def generate_ie(gen_func, state, source_text, target_text, instruct_text, source
909
  "ip": get_ip(request),
910
  }
911
  fout.write(json.dumps(data) + "\n")
912
- append_json_item_on_log_server(data, get_conv_log_filename())
913
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
914
 
915
  yield state, generated_image
@@ -1021,7 +1021,7 @@ def generate_iem(gen_func, state0, state1, source_text, target_text, instruct_te
1021
  state1.model_name = model_name1
1022
 
1023
  if generated_image0 == '' and generated_image1 == '':
1024
- with open(get_conv_log_filename(), "a") as fout:
1025
  data = {
1026
  "type": "chat",
1027
  "model": model_name0,
@@ -1031,7 +1031,7 @@ def generate_iem(gen_func, state0, state1, source_text, target_text, instruct_te
1031
  "ip": get_ip(request),
1032
  }
1033
  fout.write(json.dumps(data) + "\n")
1034
- append_json_item_on_log_server(data, get_conv_log_filename())
1035
  data = {
1036
  "type": "chat",
1037
  "model": model_name1,
@@ -1041,7 +1041,7 @@ def generate_iem(gen_func, state0, state1, source_text, target_text, instruct_te
1041
  "ip": get_ip(request),
1042
  }
1043
  fout.write(json.dumps(data) + "\n")
1044
- append_json_item_on_log_server(data, get_conv_log_filename())
1045
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1046
 
1047
 
@@ -1186,7 +1186,7 @@ def generate_iem_annoy(gen_func, state0, state1, source_text, target_text, instr
1186
  state1.output = generated_image1
1187
  state1.model_name = model_name1
1188
  if generated_image0 == '' and generated_image1 == '':
1189
- with open(get_conv_log_filename(), "a") as fout:
1190
  data = {
1191
  "type": "chat",
1192
  "model": model_name0,
@@ -1196,7 +1196,7 @@ def generate_iem_annoy(gen_func, state0, state1, source_text, target_text, instr
1196
  "ip": get_ip(request),
1197
  }
1198
  fout.write(json.dumps(data) + "\n")
1199
- append_json_item_on_log_server(data, get_conv_log_filename())
1200
  data = {
1201
  "type": "chat",
1202
  "model": model_name1,
@@ -1206,7 +1206,7 @@ def generate_iem_annoy(gen_func, state0, state1, source_text, target_text, instr
1206
  "ip": get_ip(request),
1207
  }
1208
  fout.write(json.dumps(data) + "\n")
1209
- append_json_item_on_log_server(data, get_conv_log_filename())
1210
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1211
 
1212
 
@@ -1332,7 +1332,7 @@ def generate_vg(gen_func, state, text, model_name, request: gr.Request):
1332
  state.output = generated_video
1333
  state.model_name = model_name
1334
  if generated_video == '':
1335
- with open(get_conv_log_filename(), "a") as fout:
1336
  data = {
1337
  "type": "chat",
1338
  "model": model_name,
@@ -1342,7 +1342,7 @@ def generate_vg(gen_func, state, text, model_name, request: gr.Request):
1342
  "ip": get_ip(request),
1343
  }
1344
  fout.write(json.dumps(data) + "\n")
1345
- append_json_item_on_log_server(data, get_conv_log_filename())
1346
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1347
 
1348
 
@@ -1443,7 +1443,7 @@ def generate_vgm(gen_func, state0, state1, text, model_name0, model_name1, reque
1443
  state0.model_name = model_name0
1444
  state1.model_name = model_name1
1445
  if generated_video0 == '' and generated_video1 == '':
1446
- with open(get_conv_log_filename(), "a") as fout:
1447
  data = {
1448
  "type": "chat",
1449
  "model": model_name0,
@@ -1453,7 +1453,7 @@ def generate_vgm(gen_func, state0, state1, text, model_name0, model_name1, reque
1453
  "ip": get_ip(request),
1454
  }
1455
  fout.write(json.dumps(data) + "\n")
1456
- append_json_item_on_log_server(data, get_conv_log_filename())
1457
  data = {
1458
  "type": "chat",
1459
  "model": model_name1,
@@ -1463,7 +1463,7 @@ def generate_vgm(gen_func, state0, state1, text, model_name0, model_name1, reque
1463
  "ip": get_ip(request),
1464
  }
1465
  fout.write(json.dumps(data) + "\n")
1466
- append_json_item_on_log_server(data, get_conv_log_filename())
1467
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1468
 
1469
  # yield state0, state1, generated_video0, generated_video1
@@ -1604,7 +1604,7 @@ def generate_vgm_annoy(gen_func, state0, state1, text, model_name0, model_name1,
1604
  state0.model_name = model_name0
1605
  state1.model_name = model_name1
1606
  if generated_video0 == '' and generated_video1 == '':
1607
- with open(get_conv_log_filename(), "a") as fout:
1608
  data = {
1609
  "type": "chat",
1610
  "model": model_name0,
@@ -1614,7 +1614,7 @@ def generate_vgm_annoy(gen_func, state0, state1, text, model_name0, model_name1,
1614
  "ip": get_ip(request),
1615
  }
1616
  fout.write(json.dumps(data) + "\n")
1617
- append_json_item_on_log_server(data, get_conv_log_filename())
1618
  data = {
1619
  "type": "chat",
1620
  "model": model_name1,
@@ -1624,7 +1624,7 @@ def generate_vgm_annoy(gen_func, state0, state1, text, model_name0, model_name1,
1624
  "ip": get_ip(request),
1625
  }
1626
  fout.write(json.dumps(data) + "\n")
1627
- append_json_item_on_log_server(data, get_conv_log_filename())
1628
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1629
 
1630
 
 
518
  state.output = generated_image
519
  state.model_name = model_name
520
  if generated_image == '':
521
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
522
  data = {
523
  "type": "chat",
524
  "model": model_name,
 
528
  "ip": get_ip(request),
529
  }
530
  fout.write(json.dumps(data) + "\n")
531
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
532
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
533
 
534
  yield state, generated_image
 
616
  state0.model_name = model_name0
617
  state1.model_name = model_name1
618
  if generated_image0 == '' and generated_image1 == '':
619
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
620
  data = {
621
  "type": "chat",
622
  "model": model_name0,
 
626
  "ip": get_ip(request),
627
  }
628
  fout.write(json.dumps(data) + "\n")
629
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
630
  data = {
631
  "type": "chat",
632
  "model": model_name1,
 
636
  "ip": get_ip(request),
637
  }
638
  fout.write(json.dumps(data) + "\n")
639
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
640
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
641
 
642
  yield state0, state1, generated_image0, generated_image1
 
755
  state0.model_name = model_name0
756
  state1.model_name = model_name1
757
  if generated_image0 == '' and generated_image1 == '':
758
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
759
  data = {
760
  "type": "chat",
761
  "model": model_name0,
 
765
  "ip": get_ip(request),
766
  }
767
  fout.write(json.dumps(data) + "\n")
768
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
769
  data = {
770
  "type": "chat",
771
  "model": model_name1,
 
775
  "ip": get_ip(request),
776
  }
777
  fout.write(json.dumps(data) + "\n")
778
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
779
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
780
 
781
 
 
899
  state.model_name = model_name
900
 
901
  if generated_image == '':
902
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
903
  data = {
904
  "type": "chat",
905
  "model": model_name,
 
909
  "ip": get_ip(request),
910
  }
911
  fout.write(json.dumps(data) + "\n")
912
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
913
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
914
 
915
  yield state, generated_image
 
1021
  state1.model_name = model_name1
1022
 
1023
  if generated_image0 == '' and generated_image1 == '':
1024
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
1025
  data = {
1026
  "type": "chat",
1027
  "model": model_name0,
 
1031
  "ip": get_ip(request),
1032
  }
1033
  fout.write(json.dumps(data) + "\n")
1034
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1035
  data = {
1036
  "type": "chat",
1037
  "model": model_name1,
 
1041
  "ip": get_ip(request),
1042
  }
1043
  fout.write(json.dumps(data) + "\n")
1044
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1045
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1046
 
1047
 
 
1186
  state1.output = generated_image1
1187
  state1.model_name = model_name1
1188
  if generated_image0 == '' and generated_image1 == '':
1189
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
1190
  data = {
1191
  "type": "chat",
1192
  "model": model_name0,
 
1196
  "ip": get_ip(request),
1197
  }
1198
  fout.write(json.dumps(data) + "\n")
1199
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1200
  data = {
1201
  "type": "chat",
1202
  "model": model_name1,
 
1206
  "ip": get_ip(request),
1207
  }
1208
  fout.write(json.dumps(data) + "\n")
1209
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1210
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1211
 
1212
 
 
1332
  state.output = generated_video
1333
  state.model_name = model_name
1334
  if generated_video == '':
1335
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
1336
  data = {
1337
  "type": "chat",
1338
  "model": model_name,
 
1342
  "ip": get_ip(request),
1343
  }
1344
  fout.write(json.dumps(data) + "\n")
1345
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1346
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1347
 
1348
 
 
1443
  state0.model_name = model_name0
1444
  state1.model_name = model_name1
1445
  if generated_video0 == '' and generated_video1 == '':
1446
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
1447
  data = {
1448
  "type": "chat",
1449
  "model": model_name0,
 
1453
  "ip": get_ip(request),
1454
  }
1455
  fout.write(json.dumps(data) + "\n")
1456
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1457
  data = {
1458
  "type": "chat",
1459
  "model": model_name1,
 
1463
  "ip": get_ip(request),
1464
  }
1465
  fout.write(json.dumps(data) + "\n")
1466
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1467
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1468
 
1469
  # yield state0, state1, generated_video0, generated_video1
 
1604
  state0.model_name = model_name0
1605
  state1.model_name = model_name1
1606
  if generated_video0 == '' and generated_video1 == '':
1607
+ with open(get_nsfw_conv_log_filename(), "a") as fout:
1608
  data = {
1609
  "type": "chat",
1610
  "model": model_name0,
 
1614
  "ip": get_ip(request),
1615
  }
1616
  fout.write(json.dumps(data) + "\n")
1617
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1618
  data = {
1619
  "type": "chat",
1620
  "model": model_name1,
 
1624
  "ip": get_ip(request),
1625
  }
1626
  fout.write(json.dumps(data) + "\n")
1627
+ append_json_item_on_log_server(data, get_nsfw_conv_log_filename())
1628
  raise gr.Warning("Input prompt is blocked by the NSFW filter, please input safe content and try again!")
1629
 
1630