mirabarukaso commited on
Commit
9618844
·
1 Parent(s): e7223b4

Move thumb to remote

Browse files
Files changed (3) hide show
  1. app.py +1 -9
  2. json/wai_character_thumbs.json +2 -2
  3. scripts/lib.py +16 -42
app.py CHANGED
@@ -5,7 +5,7 @@ from lib import init, refresh_character_thumb_image
5
  from lib import JAVA_SCRIPT, CSS_SCRIPT, TITLE
6
 
7
  if __name__ == '__main__':
8
- character_list, original_character_list, LANG = init()
9
 
10
  with gr.Blocks(js=JAVA_SCRIPT, css=CSS_SCRIPT, title=TITLE) as ui:
11
  with gr.Row():
@@ -29,14 +29,6 @@ if __name__ == '__main__':
29
  value='none',
30
  allow_custom_value=False,
31
  )
32
- '''
33
- original_character = gr.Dropdown(
34
- choices=original_character_list,
35
- label=LANG["original_character"],
36
- value='none',
37
- allow_custom_value=False,
38
- )
39
- '''
40
 
41
  with gr.Row(elem_classes='main_row'):
42
  with gr.Column(elem_classes='column_prompts'):
 
5
  from lib import JAVA_SCRIPT, CSS_SCRIPT, TITLE
6
 
7
  if __name__ == '__main__':
8
+ character_list, LANG = init()
9
 
10
  with gr.Blocks(js=JAVA_SCRIPT, css=CSS_SCRIPT, title=TITLE) as ui:
11
  with gr.Row():
 
29
  value='none',
30
  allow_custom_value=False,
31
  )
 
 
 
 
 
 
 
 
32
 
33
  with gr.Row(elem_classes='main_row'):
34
  with gr.Column(elem_classes='column_prompts'):
json/wai_character_thumbs.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:184e32e34ca9807614122651f9555ede639a19d7471ac0968ac0cbef22b98c62
3
- size 135382738
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e00bd43a69d59ff391b672a652f0e9b78c3fb4cc1fe146c6e08a9a425b4427cd
3
+ size 135380826
scripts/lib.py CHANGED
@@ -58,14 +58,11 @@ json_folder = os.path.join(parent_dir, 'json')
58
 
59
  character_list = ''
60
  character_dict = {}
61
- original_character_list = ''
62
- original_character_dict = {}
63
  wai_image_dict = {}
64
 
65
  wai_illustrious_character_select_files = [
66
- {'name': 'original_character', 'file_path': os.path.join(json_folder, 'original_character.json'), 'url': 'local'},
67
- {'name': 'wai_character', 'file_path': os.path.join(json_folder, 'wai_characters.csv'), 'url': 'local'},
68
- {'name': 'wai_image', 'file_path': os.path.join(json_folder, 'wai_character_thumbs.json'), 'url': 'local'},
69
  ]
70
  def get_md5_hash(input_str):
71
  md5_hash = hashlib.md5()
@@ -77,12 +74,17 @@ def base64_to_image(base64_data):
77
  webp_data = gzip.decompress(compressed_data)
78
  image = Image.open(BytesIO(webp_data))
79
  return image
 
 
 
 
 
 
 
80
 
81
  def load_jsons():
82
  global character_list
83
  global character_dict
84
- global original_character_dict
85
- global original_character_list
86
  global wai_image_dict
87
 
88
  # download file
@@ -90,11 +92,12 @@ def load_jsons():
90
  name = item['name']
91
  file_path = item['file_path']
92
  url = item['url']
 
 
 
93
 
94
- with open(file_path, 'r', encoding='utf-8') as file:
95
- if 'original_character' == name:
96
- original_character_dict.update(json.load(file))
97
- elif 'wai_character' == name:
98
  lines = file.readlines()
99
  for line in lines:
100
  key, value = line.split(',')
@@ -102,14 +105,9 @@ def load_jsons():
102
  elif 'wai_image' == name:
103
  wai_image_dict = json.load(file)
104
 
105
- # Create list
106
-
107
  character_list = list(character_dict.values())
108
-
109
  character_list.insert(0, "none")
110
-
111
- original_character_list = list(original_character_dict.keys())
112
- original_character_list.insert(0, "none")
113
 
114
  def illustrious_character_select_ex(character = 'random', optimise_tags = True, random_action_seed = 1):
115
  chara = ''
@@ -147,30 +145,6 @@ def illustrious_character_select_ex(character = 'random', optimise_tags = True,
147
 
148
  return rnd_character, opt_chara, thumb_image
149
 
150
- def original_character_select_ex(character = 'random', random_action_seed = 1):
151
- chara = ''
152
- rnd_character = ''
153
-
154
- if 'none' == character:
155
- return '', ''
156
-
157
- if 'random' == character:
158
- index = random_action_seed % len(original_character_list)
159
- rnd_character = original_character_list[index]
160
- if 'random' == rnd_character:
161
- rnd_character = original_character_list[index+2]
162
- elif 'none' == rnd_character:
163
- rnd_character = original_character_list[index+1]
164
- else:
165
- rnd_character = character
166
- chara = original_character_dict[rnd_character]
167
-
168
- opt_chara = chara
169
- if not opt_chara.endswith(','):
170
- opt_chara = f'{opt_chara},'
171
-
172
- return rnd_character, opt_chara
173
-
174
  def refresh_character_thumb_image(character1, character2, character3):
175
  thumb_image = []
176
  if 'none' != character1 and 'random' != character1:
@@ -197,4 +171,4 @@ def init():
197
  load_jsons()
198
  print(f'[{CAT}]:Starting...')
199
 
200
- return character_list, original_character_list, LANG
 
58
 
59
  character_list = ''
60
  character_dict = {}
 
 
61
  wai_image_dict = {}
62
 
63
  wai_illustrious_character_select_files = [
64
+ {'name': 'wai_character', 'file_path': os.path.join(json_folder, 'wai_characters.csv'), 'url':'https://raw.githubusercontent.com/mirabarukaso/character_select_stand_alone_app/refs/heads/main/json/wai_characters.csv'},
65
+ {'name': 'wai_image', 'file_path': os.path.join(json_folder, 'wai_character_thumbs.json'), 'url': 'https://huggingface.co/datasets/flagrantia/character_select_stand_alone_app/resolve/main/wai_character_thumbs.json'},
 
66
  ]
67
  def get_md5_hash(input_str):
68
  md5_hash = hashlib.md5()
 
74
  webp_data = gzip.decompress(compressed_data)
75
  image = Image.open(BytesIO(webp_data))
76
  return image
77
+
78
+ def download_file(url, file_path):
79
+ response = requests.get(url)
80
+ response.raise_for_status()
81
+ print(f'[{CAT}]:Downloading... {url}')
82
+ with open(file_path, 'wb') as file:
83
+ file.write(response.content)
84
 
85
  def load_jsons():
86
  global character_list
87
  global character_dict
 
 
88
  global wai_image_dict
89
 
90
  # download file
 
92
  name = item['name']
93
  file_path = item['file_path']
94
  url = item['url']
95
+
96
+ if not os.path.exists(file_path):
97
+ download_file(url, file_path)
98
 
99
+ with open(file_path, 'r', encoding='utf-8') as file:
100
+ if 'wai_character' == name:
 
 
101
  lines = file.readlines()
102
  for line in lines:
103
  key, value = line.split(',')
 
105
  elif 'wai_image' == name:
106
  wai_image_dict = json.load(file)
107
 
108
+ # Create list
 
109
  character_list = list(character_dict.values())
 
110
  character_list.insert(0, "none")
 
 
 
111
 
112
  def illustrious_character_select_ex(character = 'random', optimise_tags = True, random_action_seed = 1):
113
  chara = ''
 
145
 
146
  return rnd_character, opt_chara, thumb_image
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  def refresh_character_thumb_image(character1, character2, character3):
149
  thumb_image = []
150
  if 'none' != character1 and 'random' != character1:
 
171
  load_jsons()
172
  print(f'[{CAT}]:Starting...')
173
 
174
+ return character_list, LANG