drakosfire commited on
Commit
10d95be
1 Parent(s): 0f19a78

function added to user_input to get index from git directory

Browse files
__pycache__/card_generator.cpython-310.pyc CHANGED
Binary files a/__pycache__/card_generator.cpython-310.pyc and b/__pycache__/card_generator.cpython-310.pyc differ
 
__pycache__/img2img.cpython-310.pyc CHANGED
Binary files a/__pycache__/img2img.cpython-310.pyc and b/__pycache__/img2img.cpython-310.pyc differ
 
__pycache__/item_dict_gen.cpython-310.pyc CHANGED
Binary files a/__pycache__/item_dict_gen.cpython-310.pyc and b/__pycache__/item_dict_gen.cpython-310.pyc differ
 
__pycache__/render_card_text.cpython-310.pyc CHANGED
Binary files a/__pycache__/render_card_text.cpython-310.pyc and b/__pycache__/render_card_text.cpython-310.pyc differ
 
__pycache__/template_builder.cpython-310.pyc CHANGED
Binary files a/__pycache__/template_builder.cpython-310.pyc and b/__pycache__/template_builder.cpython-310.pyc differ
 
__pycache__/user_input.cpython-310.pyc CHANGED
Binary files a/__pycache__/user_input.cpython-310.pyc and b/__pycache__/user_input.cpython-310.pyc differ
 
__pycache__/utilities.cpython-310.pyc CHANGED
Binary files a/__pycache__/utilities.cpython-310.pyc and b/__pycache__/utilities.cpython-310.pyc differ
 
main.py CHANGED
@@ -6,10 +6,6 @@ import ctypes
6
  import user_input as useri
7
  import gradio as gr
8
  import template_builder as tb
9
- import threading
10
- import time
11
-
12
-
13
 
14
  # This is a fix for the way that python doesn't release system memory back to the OS and it was leading to locking up the system
15
  libc = ctypes.cdll.LoadLibrary("libc.so.6")
@@ -19,10 +15,6 @@ M_MMAP_THRESHOLD = -3
19
  libc.mallopt(M_MMAP_THRESHOLD, 2**20)
20
  initial_name = "A Crowbar"
21
 
22
-
23
-
24
-
25
-
26
  with gr.Blocks() as demo:
27
 
28
  # Functions and State Variables
@@ -62,21 +54,11 @@ with gr.Blocks() as demo:
62
  def set_textbox_defaults(textbox_default_dict, key):
63
  item_name = textbox_default_dict[key]
64
  return item_name
65
-
66
-
67
-
68
  # Function called when user generates item info, then assign values of dictionary to variables, output once to State, twice to textbox
69
- def generate_text_update_textboxes(user_input, progress = gr.Progress()):
70
  u.reclaim_mem()
71
-
72
- # Define a function to update progress
73
- def update_progress(duration, progress):
74
- for i in range(10):
75
- time.sleep(duration / 10) # Wait for a fraction of the total duration
76
- progress((i + 1) / 10, desc="Thinking...") # Update progress
77
- # Start the progress update in a separate thread, passing `progress` explicitly
78
- threading.Thread(target=update_progress, args=(10, progress)).start()
79
-
80
  llm_output=useri.call_llm(user_input)
81
  item_key = list(llm_output.keys())
82
 
@@ -90,11 +72,12 @@ with gr.Blocks() as demo:
90
  if 'Damage' in item_key_values:
91
  item_damage = llm_output[item_key[0]]['Damage']
92
  else: item_damage = ''
 
93
  item_weight = llm_output[item_key[0]]['Weight']
94
  item_description = llm_output[item_key[0]]['Description']
95
- item_quote = llm_output[item_key[0]]['Quote']
96
-
97
  sd_prompt = llm_output[item_key[0]]['SD Prompt']
 
98
  return [item_name, item_name,
99
  item_type, item_type,
100
  item_rarity, item_rarity,
@@ -142,14 +125,14 @@ with gr.Blocks() as demo:
142
  return image_list, image_list
143
 
144
 
145
- # Beginning of page format
146
- # Title
147
  gr.HTML(""" <div id="inner"> <header>
148
  <h1>Item Card Generator</h1>
149
  <p>
150
  With this AI driven tool you will build a collectible style card of a fantasy flavored item with details.
151
  </p>
152
  </div>""")
 
153
  gr.HTML(""" <div id="inner"> <header>
154
  <h2><b>First:</b> Build a Card Template</h2>
155
  </div>""")
@@ -162,32 +145,31 @@ with gr.Blocks() as demo:
162
 
163
  border_gallery = gr.Gallery(label = "Card Template Gallery",
164
  scale = 2,
165
- value = useri.index_image_paths("./seed_images/card_templates/", "card_templates/"),
166
  show_label = True,
167
  columns = [3], rows = [3],
168
  object_fit = "contain",
169
  height = "auto",
170
  elem_id = "Template Gallery")
 
171
  gr.HTML(""" <div id="inner"> <header>
172
  <h3>2. Click a image from the Seed Image Gallery</h3><br>
173
  </div>""")
 
174
  border_gallery.select(assign_img_path, outputs = selected_border_image)
175
-
176
  seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
177
  scale = 2,
178
- value = useri.index_image_paths("./seed_images/item_seeds/","item_seeds/"),
179
  show_label = True,
180
  columns = [3], rows = [3],
181
  object_fit = "contain",
182
  height = "auto",
183
  elem_id = "Template Gallery",
184
- interactive=True)
185
-
186
 
187
  gr.HTML(""" <div id="inner"> <header><h4> -Or- Upload your own seed image, by dropping it into the 'Generated Template Gallery' </h4><br>
188
  <h3>3. Click 'Generate Card Template'</h3><br>
189
  </div>""")
190
-
191
 
192
  built_template_gallery = gr.Gallery(label= "Generated Template Gallery",
193
  scale = 1,
@@ -201,7 +183,6 @@ with gr.Blocks() as demo:
201
 
202
  seed_image_gallery.select(assign_img_path, outputs = selected_seed_image)
203
  built_template_gallery.upload(u.receive_upload, inputs=built_template_gallery, outputs= selected_seed_image)
204
-
205
  build_card_template_button = gr.Button(value = "Generate Card Template")
206
  build_card_template_button.click(build_template, inputs = [selected_border_image, selected_seed_image], outputs = [built_template_gallery, built_template])
207
 
@@ -212,8 +193,6 @@ with gr.Blocks() as demo:
212
  <h3>1. Use a few words to describe the item then click 'Generate Text' </h3>
213
  </div>""")
214
  with gr.Row():
215
-
216
-
217
  user_input = gr.Textbox(label = 'Item', lines =1, placeholder= "Flaming Magical Sword", elem_id= "Item", scale =4)
218
  item_text_generate = gr.Button(value = "Generate item text", scale=1)
219
 
@@ -221,12 +200,9 @@ with gr.Blocks() as demo:
221
  <h3> 2. Review and Edit the text</h3>
222
  </div>""")
223
  with gr.Row():
224
- # Build text boxes for the broken up item dictionary values
225
-
226
  with gr.Column(scale = 1):
227
-
228
-
229
-
230
  item_name_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Name'),label = 'Name', lines = 1, interactive=True, elem_id='Item Name')
231
  item_type_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Type'),label = 'Type', lines = 1, interactive=True, elem_id='Item Type')
232
  item_rarity_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Rarity'),label = 'Rarity : [Common, Uncommon, Rare, Very Rare, Legendary]', lines = 1, interactive=True, elem_id='Item Rarity')
@@ -239,6 +215,7 @@ with gr.Blocks() as demo:
239
  item_description_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Description'),label = 'Description', lines = 1, interactive=True, elem_id='Item Description')
240
  item_quote_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Quote'),label = 'Quote', lines = 1, interactive=True, elem_id='Item quote')
241
  item_properties_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Properties'),label = 'Properties : [List of comma seperated values]', lines = 1, interactive=True, elem_id='Item Properties')
 
242
  gr.HTML(""" <div id="inner"> <header>
243
  <h3> 3. This text will be used to generate the card's image.</h3>
244
  </div>""")
@@ -267,7 +244,6 @@ with gr.Blocks() as demo:
267
  )
268
  generate_final_item_card = gr.Button(value = "Add Text", elem_id = "Generate user card")
269
 
270
-
271
  card_gen_button.click(fn = generate_image_update_gallery, inputs =[num_image_to_generate,item_sd_prompt_output,item_name_output,built_template], outputs= generate_gallery)
272
  generate_gallery.select(assign_img_path, outputs = selected_generated_image)
273
 
@@ -295,8 +271,6 @@ with gr.Blocks() as demo:
295
  item_sd_prompt_var,
296
  item_sd_prompt_output])
297
 
298
-
299
-
300
  generate_final_item_card.click(card.render_text_on_card, inputs = [selected_generated_image,
301
  item_name_output,
302
  item_type_output,
@@ -310,8 +284,6 @@ with gr.Blocks() as demo:
310
  ],
311
  outputs = generate_gallery )
312
 
313
-
314
-
315
  if __name__ == '__main__':
316
  demo.launch(server_name = "0.0.0.0", server_port = 8000, share = False, allowed_paths = ["/media/drakosfire/Shared/","/media/drakosfire/Shared/MerchantBot/card_templates"])
317
 
 
6
  import user_input as useri
7
  import gradio as gr
8
  import template_builder as tb
 
 
 
 
9
 
10
  # This is a fix for the way that python doesn't release system memory back to the OS and it was leading to locking up the system
11
  libc = ctypes.cdll.LoadLibrary("libc.so.6")
 
15
  libc.mallopt(M_MMAP_THRESHOLD, 2**20)
16
  initial_name = "A Crowbar"
17
 
 
 
 
 
18
  with gr.Blocks() as demo:
19
 
20
  # Functions and State Variables
 
54
  def set_textbox_defaults(textbox_default_dict, key):
55
  item_name = textbox_default_dict[key]
56
  return item_name
57
+
 
 
58
  # Function called when user generates item info, then assign values of dictionary to variables, output once to State, twice to textbox
59
+ def generate_text_update_textboxes(user_input):
60
  u.reclaim_mem()
61
+
 
 
 
 
 
 
 
 
62
  llm_output=useri.call_llm(user_input)
63
  item_key = list(llm_output.keys())
64
 
 
72
  if 'Damage' in item_key_values:
73
  item_damage = llm_output[item_key[0]]['Damage']
74
  else: item_damage = ''
75
+
76
  item_weight = llm_output[item_key[0]]['Weight']
77
  item_description = llm_output[item_key[0]]['Description']
78
+ item_quote = llm_output[item_key[0]]['Quote']
 
79
  sd_prompt = llm_output[item_key[0]]['SD Prompt']
80
+
81
  return [item_name, item_name,
82
  item_type, item_type,
83
  item_rarity, item_rarity,
 
125
  return image_list, image_list
126
 
127
 
128
+ # Beginning of UI Page
 
129
  gr.HTML(""" <div id="inner"> <header>
130
  <h1>Item Card Generator</h1>
131
  <p>
132
  With this AI driven tool you will build a collectible style card of a fantasy flavored item with details.
133
  </p>
134
  </div>""")
135
+
136
  gr.HTML(""" <div id="inner"> <header>
137
  <h2><b>First:</b> Build a Card Template</h2>
138
  </div>""")
 
145
 
146
  border_gallery = gr.Gallery(label = "Card Template Gallery",
147
  scale = 2,
148
+ value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/card_templates"),
149
  show_label = True,
150
  columns = [3], rows = [3],
151
  object_fit = "contain",
152
  height = "auto",
153
  elem_id = "Template Gallery")
154
+
155
  gr.HTML(""" <div id="inner"> <header>
156
  <h3>2. Click a image from the Seed Image Gallery</h3><br>
157
  </div>""")
158
+
159
  border_gallery.select(assign_img_path, outputs = selected_border_image)
 
160
  seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
161
  scale = 2,
162
+ value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/item_seeds"),
163
  show_label = True,
164
  columns = [3], rows = [3],
165
  object_fit = "contain",
166
  height = "auto",
167
  elem_id = "Template Gallery",
168
+ interactive=True)
 
169
 
170
  gr.HTML(""" <div id="inner"> <header><h4> -Or- Upload your own seed image, by dropping it into the 'Generated Template Gallery' </h4><br>
171
  <h3>3. Click 'Generate Card Template'</h3><br>
172
  </div>""")
 
173
 
174
  built_template_gallery = gr.Gallery(label= "Generated Template Gallery",
175
  scale = 1,
 
183
 
184
  seed_image_gallery.select(assign_img_path, outputs = selected_seed_image)
185
  built_template_gallery.upload(u.receive_upload, inputs=built_template_gallery, outputs= selected_seed_image)
 
186
  build_card_template_button = gr.Button(value = "Generate Card Template")
187
  build_card_template_button.click(build_template, inputs = [selected_border_image, selected_seed_image], outputs = [built_template_gallery, built_template])
188
 
 
193
  <h3>1. Use a few words to describe the item then click 'Generate Text' </h3>
194
  </div>""")
195
  with gr.Row():
 
 
196
  user_input = gr.Textbox(label = 'Item', lines =1, placeholder= "Flaming Magical Sword", elem_id= "Item", scale =4)
197
  item_text_generate = gr.Button(value = "Generate item text", scale=1)
198
 
 
200
  <h3> 2. Review and Edit the text</h3>
201
  </div>""")
202
  with gr.Row():
203
+
204
+ # Build text boxes for the broken up item dictionary values
205
  with gr.Column(scale = 1):
 
 
 
206
  item_name_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Name'),label = 'Name', lines = 1, interactive=True, elem_id='Item Name')
207
  item_type_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Type'),label = 'Type', lines = 1, interactive=True, elem_id='Item Type')
208
  item_rarity_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Rarity'),label = 'Rarity : [Common, Uncommon, Rare, Very Rare, Legendary]', lines = 1, interactive=True, elem_id='Item Rarity')
 
215
  item_description_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Description'),label = 'Description', lines = 1, interactive=True, elem_id='Item Description')
216
  item_quote_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Quote'),label = 'Quote', lines = 1, interactive=True, elem_id='Item quote')
217
  item_properties_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Properties'),label = 'Properties : [List of comma seperated values]', lines = 1, interactive=True, elem_id='Item Properties')
218
+
219
  gr.HTML(""" <div id="inner"> <header>
220
  <h3> 3. This text will be used to generate the card's image.</h3>
221
  </div>""")
 
244
  )
245
  generate_final_item_card = gr.Button(value = "Add Text", elem_id = "Generate user card")
246
 
 
247
  card_gen_button.click(fn = generate_image_update_gallery, inputs =[num_image_to_generate,item_sd_prompt_output,item_name_output,built_template], outputs= generate_gallery)
248
  generate_gallery.select(assign_img_path, outputs = selected_generated_image)
249
 
 
271
  item_sd_prompt_var,
272
  item_sd_prompt_output])
273
 
 
 
274
  generate_final_item_card.click(card.render_text_on_card, inputs = [selected_generated_image,
275
  item_name_output,
276
  item_type_output,
 
284
  ],
285
  outputs = generate_gallery )
286
 
 
 
287
  if __name__ == '__main__':
288
  demo.launch(server_name = "0.0.0.0", server_port = 8000, share = False, allowed_paths = ["/media/drakosfire/Shared/","/media/drakosfire/Shared/MerchantBot/card_templates"])
289
 
user_input.py CHANGED
@@ -5,21 +5,25 @@ import utilities as u
5
  import sys
6
  import tempfile
7
  from PIL import Image
 
8
 
9
  image_path = str
10
  end_phrase = """<|end_of_turn|>"""
11
  # Indexing the contents of Card templates and temp images
12
  card_template_path = "./card_templates/"
13
  temp_image_path = "./image_temp"
14
- def index_image_paths(directory_path, github_path):
15
- list_temp_files = []
16
- list_of_image_paths = u.directory_contents(directory_path)
17
- for image_path in list_of_image_paths:
18
- image_path = f"https://raw.githubusercontent.com/Drakosfire/CardGenerator/alpha-templates/seed_images/{github_path}{image_path}"
19
- print(image_path)
20
- list_temp_files.append(image_path)
21
- return list_temp_files
22
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  user_pick_template_prompt = "Pick a template number from this list : "
25
  user_pick_image_prompt = "Select an image : "
@@ -76,6 +80,7 @@ def prompt_user_input():
76
  mimic = True
77
 
78
  #user_input_template = input(f"Pick a template number from this list : {process_list_for_user_response(list_of_card_templates)}")
 
79
  user_input_template = user_pick_item(user_pick_template_prompt,list_of_card_templates)
80
  response = call_llm(user_input_item)
81
  print(response[u.keys_list(response,0)])
 
5
  import sys
6
  import tempfile
7
  from PIL import Image
8
+ from github import Github
9
 
10
  image_path = str
11
  end_phrase = """<|end_of_turn|>"""
12
  # Indexing the contents of Card templates and temp images
13
  card_template_path = "./card_templates/"
14
  temp_image_path = "./image_temp"
 
 
 
 
 
 
 
 
15
 
16
+ def index_image_paths(repo_name,directory_path):
17
+ g = Github() # No token needed for public repos
18
+ repo = g.get_repo(repo_name)
19
+ contents = repo.get_contents(directory_path)
20
+
21
+ files = []
22
+ for content_file in contents:
23
+ if content_file.type == "file":
24
+ files.append(content_file.download_url) # Or content_file.path for just the path
25
+
26
+ return files
27
 
28
  user_pick_template_prompt = "Pick a template number from this list : "
29
  user_pick_image_prompt = "Select an image : "
 
80
  mimic = True
81
 
82
  #user_input_template = input(f"Pick a template number from this list : {process_list_for_user_response(list_of_card_templates)}")
83
+
84
  user_input_template = user_pick_item(user_pick_template_prompt,list_of_card_templates)
85
  response = call_llm(user_input_item)
86
  print(response[u.keys_list(response,0)])