Spaces:
Sleeping
Sleeping
drakosfire
commited on
Commit
•
0f3ebe6
1
Parent(s):
cb26647
new baseline, git lfs issues resolved, repo clean
Browse files- .gitattributes +3 -5
- .gitignore +1 -0
- __pycache__/card_generator.cpython-310.pyc +0 -0
- __pycache__/item_dict_gen.cpython-310.pyc +0 -0
- __pycache__/user_input.cpython-310.pyc +0 -0
- card_generator.py +0 -4
- item_dict_gen.py +0 -16
- main.py +3 -114
- user_input.py +0 -21
.gitattributes
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
-
|
2 |
-
<<<<<<< HEAD
|
3 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
4 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
5 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
@@ -35,9 +34,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
35 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
36 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
37 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
38 |
-
=======
|
39 |
-
*.png filter=lfs diff=lfs merge=lfs -text
|
40 |
|
41 |
-
=======
|
42 |
*.png filter=lfs diff=lfs merge=lfs -text
|
43 |
|
|
|
|
|
|
1 |
+
|
|
|
2 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
3 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
4 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
34 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
35 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
36 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
37 |
|
|
|
38 |
*.png filter=lfs diff=lfs merge=lfs -text
|
39 |
|
40 |
+
|
41 |
+
|
.gitignore
CHANGED
@@ -4,5 +4,6 @@ models
|
|
4 |
seed_images/
|
5 |
cuda_12.4.0_550.54.14_linux.run
|
6 |
models/
|
|
|
7 |
|
8 |
|
|
|
4 |
seed_images/
|
5 |
cuda_12.4.0_550.54.14_linux.run
|
6 |
models/
|
7 |
+
blobs-ids.txt
|
8 |
|
9 |
|
__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__/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__/user_input.cpython-310.pyc
CHANGED
Binary files a/__pycache__/user_input.cpython-310.pyc and b/__pycache__/user_input.cpython-310.pyc differ
|
|
card_generator.py
CHANGED
@@ -23,11 +23,7 @@ test_item = {'Name': 'Pustulent Raspberry', 'Type': 'Fruit', 'Value': '1 cp', 'P
|
|
23 |
# Function that takes in an image url and a dictionary and uses the values to print onto a card.
|
24 |
def paste_image_and_resize(base_image,sticker_path, x_position, y_position,img_width, img_height, purchased_item_key = None):
|
25 |
|
26 |
-
<<<<<<< HEAD
|
27 |
# Check for if item has a Rarity string that is in the dictionary of sticker paths
|
28 |
-
=======
|
29 |
-
# Check for if item has a Rarity string that is a in the dictionary of sticket paths
|
30 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
31 |
if purchased_item_key:
|
32 |
if sticker_path[purchased_item_key]:
|
33 |
sticker_path = sticker_path[purchased_item_key]
|
|
|
23 |
# Function that takes in an image url and a dictionary and uses the values to print onto a card.
|
24 |
def paste_image_and_resize(base_image,sticker_path, x_position, y_position,img_width, img_height, purchased_item_key = None):
|
25 |
|
|
|
26 |
# Check for if item has a Rarity string that is in the dictionary of sticker paths
|
|
|
|
|
|
|
27 |
if purchased_item_key:
|
28 |
if sticker_path[purchased_item_key]:
|
29 |
sticker_path = sticker_path[purchased_item_key]
|
item_dict_gen.py
CHANGED
@@ -4,32 +4,16 @@ import gc
|
|
4 |
import torch
|
5 |
|
6 |
model_path = "./models/starling-lm-7b-alpha.Q8_0.gguf"
|
7 |
-
<<<<<<< HEAD
|
8 |
-
|
9 |
-
=======
|
10 |
-
# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
|
11 |
-
|
12 |
-
|
13 |
-
# Simple inference example
|
14 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
15 |
def load_llm(user_input):
|
16 |
llm = Llama(
|
17 |
model_path=model_path,
|
18 |
n_ctx=8192, # The max sequence length to use - note that longer sequence lengths require much more resources
|
19 |
n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
|
20 |
-
<<<<<<< HEAD
|
21 |
n_gpu_layers=32 # The number of layers to offload to GPU, if you have GPU acceleration available
|
22 |
)
|
23 |
return llm(
|
24 |
f"GPT4 User: {prompt_instructions} the item is {user_input}: <|end_of_turn|>GPT4 Assistant:", # Prompt
|
25 |
max_tokens=768, # Generate up to 512 tokens
|
26 |
-
=======
|
27 |
-
n_gpu_layers=-1 # The number of layers to offload to GPU, if you have GPU acceleration available
|
28 |
-
)
|
29 |
-
return llm(
|
30 |
-
f"GPT4 User: {prompt_instructions} the item is {user_input}: <|end_of_turn|>GPT4 Assistant:", # Prompt
|
31 |
-
max_tokens=512, # Generate up to 512 tokens
|
32 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
33 |
stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.
|
34 |
echo=False # Whether to echo the prompt
|
35 |
)
|
|
|
4 |
import torch
|
5 |
|
6 |
model_path = "./models/starling-lm-7b-alpha.Q8_0.gguf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def load_llm(user_input):
|
8 |
llm = Llama(
|
9 |
model_path=model_path,
|
10 |
n_ctx=8192, # The max sequence length to use - note that longer sequence lengths require much more resources
|
11 |
n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
|
|
|
12 |
n_gpu_layers=32 # The number of layers to offload to GPU, if you have GPU acceleration available
|
13 |
)
|
14 |
return llm(
|
15 |
f"GPT4 User: {prompt_instructions} the item is {user_input}: <|end_of_turn|>GPT4 Assistant:", # Prompt
|
16 |
max_tokens=768, # Generate up to 512 tokens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.
|
18 |
echo=False # Whether to echo the prompt
|
19 |
)
|
main.py
CHANGED
@@ -6,13 +6,6 @@ import ctypes
|
|
6 |
import user_input as useri
|
7 |
import gradio as gr
|
8 |
import template_builder as tb
|
9 |
-
<<<<<<< HEAD
|
10 |
-
=======
|
11 |
-
import threading
|
12 |
-
import time
|
13 |
-
|
14 |
-
|
15 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
16 |
|
17 |
# 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
|
18 |
libc = ctypes.cdll.LoadLibrary("libc.so.6")
|
@@ -22,13 +15,6 @@ M_MMAP_THRESHOLD = -3
|
|
22 |
libc.mallopt(M_MMAP_THRESHOLD, 2**20)
|
23 |
initial_name = "A Crowbar"
|
24 |
|
25 |
-
<<<<<<< HEAD
|
26 |
-
=======
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
32 |
with gr.Blocks() as demo:
|
33 |
|
34 |
# Functions and State Variables
|
@@ -68,32 +54,13 @@ with gr.Blocks() as demo:
|
|
68 |
def set_textbox_defaults(textbox_default_dict, key):
|
69 |
item_name = textbox_default_dict[key]
|
70 |
return item_name
|
71 |
-
<<<<<<< HEAD
|
72 |
|
73 |
|
74 |
# Function called when user generates item info, then assign values of dictionary to variables, output once to State, twice to textbox
|
75 |
-
def generate_text_update_textboxes(user_input):
|
76 |
def generate_text_update_textboxes(user_input):
|
77 |
u.reclaim_mem()
|
78 |
|
79 |
|
80 |
-
=======
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
# Function called when user generates item info, then assign values of dictionary to variables, output once to State, twice to textbox
|
85 |
-
def generate_text_update_textboxes(user_input, progress = gr.Progress()):
|
86 |
-
u.reclaim_mem()
|
87 |
-
|
88 |
-
# Define a function to update progress
|
89 |
-
def update_progress(duration, progress):
|
90 |
-
for i in range(10):
|
91 |
-
time.sleep(duration / 10) # Wait for a fraction of the total duration
|
92 |
-
progress((i + 1) / 10, desc="Thinking...") # Update progress
|
93 |
-
# Start the progress update in a separate thread, passing `progress` explicitly
|
94 |
-
threading.Thread(target=update_progress, args=(10, progress)).start()
|
95 |
-
|
96 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
97 |
llm_output=useri.call_llm(user_input)
|
98 |
item_key = list(llm_output.keys())
|
99 |
|
@@ -107,7 +74,6 @@ with gr.Blocks() as demo:
|
|
107 |
if 'Damage' in item_key_values:
|
108 |
item_damage = llm_output[item_key[0]]['Damage']
|
109 |
else: item_damage = ''
|
110 |
-
<<<<<<< HEAD
|
111 |
|
112 |
|
113 |
item_weight = llm_output[item_key[0]]['Weight']
|
@@ -117,13 +83,6 @@ with gr.Blocks() as demo:
|
|
117 |
sd_prompt = llm_output[item_key[0]]['SD Prompt']
|
118 |
|
119 |
|
120 |
-
=======
|
121 |
-
item_weight = llm_output[item_key[0]]['Weight']
|
122 |
-
item_description = llm_output[item_key[0]]['Description']
|
123 |
-
item_quote = llm_output[item_key[0]]['Quote']
|
124 |
-
|
125 |
-
sd_prompt = llm_output[item_key[0]]['SD Prompt']
|
126 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
127 |
return [item_name, item_name,
|
128 |
item_type, item_type,
|
129 |
item_rarity, item_rarity,
|
@@ -171,51 +130,35 @@ with gr.Blocks() as demo:
|
|
171 |
return image_list, image_list
|
172 |
|
173 |
|
174 |
-
<<<<<<< HEAD
|
175 |
# Beginning of UI Page
|
176 |
# Beginning of UI Page
|
177 |
-
=======
|
178 |
-
# Beginning of page format
|
179 |
-
# Title
|
180 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
181 |
gr.HTML(""" <div id="inner"> <header>
|
182 |
<h1>Item Card Generator</h1>
|
183 |
<p>
|
184 |
With this AI driven tool you will build a collectible style card of a fantasy flavored item with details.
|
185 |
</p>
|
186 |
</div>""")
|
187 |
-
<<<<<<< HEAD
|
188 |
|
189 |
|
190 |
-
=======
|
191 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
192 |
gr.HTML(""" <div id="inner"> <header>
|
193 |
<h2><b>First:</b> Build a Card Template</h2>
|
194 |
</div>""")
|
195 |
with gr.Row():
|
196 |
-
<<<<<<< HEAD
|
197 |
with gr.Column():
|
198 |
-
=======
|
199 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
200 |
|
201 |
# Template Gallery instructions
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
|
206 |
border_gallery = gr.Gallery(label = "Card Template Gallery",
|
207 |
scale = 2,
|
208 |
-
<<<<<<< HEAD
|
209 |
value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/card_templates"),
|
210 |
-
=======
|
211 |
-
value = useri.index_image_paths("./seed_images/card_templates/", "card_templates/"),
|
212 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
213 |
show_label = True,
|
214 |
columns = [3], rows = [3],
|
215 |
object_fit = "contain",
|
216 |
height = "auto",
|
217 |
elem_id = "Template Gallery")
|
218 |
-
<<<<<<< HEAD
|
219 |
|
220 |
gr.HTML(""" <div id="inner"> <header>
|
221 |
<h3>2. Click a image from the Seed Image Gallery</h3><br>
|
@@ -225,35 +168,16 @@ with gr.Blocks() as demo:
|
|
225 |
seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
|
226 |
scale = 2,
|
227 |
value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/item_seeds"),
|
228 |
-
=======
|
229 |
-
gr.HTML(""" <div id="inner"> <header>
|
230 |
-
<h3>2. Click a image from the Seed Image Gallery</h3><br>
|
231 |
-
</div>""")
|
232 |
-
border_gallery.select(assign_img_path, outputs = selected_border_image)
|
233 |
-
|
234 |
-
seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
|
235 |
-
scale = 2,
|
236 |
-
value = useri.index_image_paths("./seed_images/item_seeds/","item_seeds/"),
|
237 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
238 |
show_label = True,
|
239 |
columns = [3], rows = [3],
|
240 |
object_fit = "contain",
|
241 |
height = "auto",
|
242 |
elem_id = "Template Gallery",
|
243 |
-
<<<<<<< HEAD
|
244 |
interactive=True)
|
245 |
-
=======
|
246 |
-
interactive=True)
|
247 |
-
|
248 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
249 |
|
250 |
gr.HTML(""" <div id="inner"> <header><h4> -Or- Upload your own seed image, by dropping it into the 'Generated Template Gallery' </h4><br>
|
251 |
<h3>3. Click 'Generate Card Template'</h3><br>
|
252 |
</div>""")
|
253 |
-
<<<<<<< HEAD
|
254 |
-
=======
|
255 |
-
|
256 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
257 |
|
258 |
built_template_gallery = gr.Gallery(label= "Generated Template Gallery",
|
259 |
scale = 1,
|
@@ -267,10 +191,6 @@ with gr.Blocks() as demo:
|
|
267 |
|
268 |
seed_image_gallery.select(assign_img_path, outputs = selected_seed_image)
|
269 |
built_template_gallery.upload(u.receive_upload, inputs=built_template_gallery, outputs= selected_seed_image)
|
270 |
-
<<<<<<< HEAD
|
271 |
-
=======
|
272 |
-
|
273 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
274 |
build_card_template_button = gr.Button(value = "Generate Card Template")
|
275 |
build_card_template_button.click(build_template, inputs = [selected_border_image, selected_seed_image], outputs = [built_template_gallery, built_template])
|
276 |
|
@@ -281,11 +201,6 @@ with gr.Blocks() as demo:
|
|
281 |
<h3>1. Use a few words to describe the item then click 'Generate Text' </h3>
|
282 |
</div>""")
|
283 |
with gr.Row():
|
284 |
-
<<<<<<< HEAD
|
285 |
-
=======
|
286 |
-
|
287 |
-
|
288 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
289 |
user_input = gr.Textbox(label = 'Item', lines =1, placeholder= "Flaming Magical Sword", elem_id= "Item", scale =4)
|
290 |
item_text_generate = gr.Button(value = "Generate item text", scale=1)
|
291 |
|
@@ -293,20 +208,11 @@ with gr.Blocks() as demo:
|
|
293 |
<h3> 2. Review and Edit the text</h3>
|
294 |
</div>""")
|
295 |
with gr.Row():
|
296 |
-
<<<<<<< HEAD
|
297 |
|
298 |
# Build text boxes for the broken up item dictionary values
|
299 |
|
300 |
# Build text boxes for the broken up item dictionary values
|
301 |
with gr.Column(scale = 1):
|
302 |
-
=======
|
303 |
-
# Build text boxes for the broken up item dictionary values
|
304 |
-
|
305 |
-
with gr.Column(scale = 1):
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
310 |
item_name_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Name'),label = 'Name', lines = 1, interactive=True, elem_id='Item Name')
|
311 |
item_type_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Type'),label = 'Type', lines = 1, interactive=True, elem_id='Item Type')
|
312 |
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')
|
@@ -319,11 +225,8 @@ with gr.Blocks() as demo:
|
|
319 |
item_description_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Description'),label = 'Description', lines = 1, interactive=True, elem_id='Item Description')
|
320 |
item_quote_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Quote'),label = 'Quote', lines = 1, interactive=True, elem_id='Item quote')
|
321 |
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')
|
322 |
-
<<<<<<< HEAD
|
323 |
|
324 |
|
325 |
-
=======
|
326 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
327 |
gr.HTML(""" <div id="inner"> <header>
|
328 |
<h3> 3. This text will be used to generate the card's image.</h3>
|
329 |
</div>""")
|
@@ -352,11 +255,7 @@ with gr.Blocks() as demo:
|
|
352 |
)
|
353 |
generate_final_item_card = gr.Button(value = "Add Text", elem_id = "Generate user card")
|
354 |
|
355 |
-
<<<<<<< HEAD
|
356 |
|
357 |
-
=======
|
358 |
-
|
359 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
360 |
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)
|
361 |
generate_gallery.select(assign_img_path, outputs = selected_generated_image)
|
362 |
|
@@ -384,12 +283,7 @@ with gr.Blocks() as demo:
|
|
384 |
item_sd_prompt_var,
|
385 |
item_sd_prompt_output])
|
386 |
|
387 |
-
<<<<<<< HEAD
|
388 |
|
389 |
-
=======
|
390 |
-
|
391 |
-
|
392 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
393 |
generate_final_item_card.click(card.render_text_on_card, inputs = [selected_generated_image,
|
394 |
item_name_output,
|
395 |
item_type_output,
|
@@ -403,12 +297,7 @@ with gr.Blocks() as demo:
|
|
403 |
],
|
404 |
outputs = generate_gallery )
|
405 |
|
406 |
-
<<<<<<< HEAD
|
407 |
|
408 |
-
=======
|
409 |
-
|
410 |
-
|
411 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
412 |
if __name__ == '__main__':
|
413 |
demo.launch(server_name = "0.0.0.0", server_port = 8000, share = False, allowed_paths = ["/media/drakosfire/Shared/","/media/drakosfire/Shared/MerchantBot/card_templates"])
|
414 |
|
|
|
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 |
|
59 |
# Function called when user generates item info, then assign values of dictionary to variables, output once to State, twice to textbox
|
|
|
60 |
def generate_text_update_textboxes(user_input):
|
61 |
u.reclaim_mem()
|
62 |
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
llm_output=useri.call_llm(user_input)
|
65 |
item_key = list(llm_output.keys())
|
66 |
|
|
|
74 |
if 'Damage' in item_key_values:
|
75 |
item_damage = llm_output[item_key[0]]['Damage']
|
76 |
else: item_damage = ''
|
|
|
77 |
|
78 |
|
79 |
item_weight = llm_output[item_key[0]]['Weight']
|
|
|
83 |
sd_prompt = llm_output[item_key[0]]['SD Prompt']
|
84 |
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
return [item_name, item_name,
|
87 |
item_type, item_type,
|
88 |
item_rarity, item_rarity,
|
|
|
130 |
return image_list, image_list
|
131 |
|
132 |
|
|
|
133 |
# Beginning of UI Page
|
134 |
# Beginning of UI Page
|
|
|
|
|
|
|
|
|
135 |
gr.HTML(""" <div id="inner"> <header>
|
136 |
<h1>Item Card Generator</h1>
|
137 |
<p>
|
138 |
With this AI driven tool you will build a collectible style card of a fantasy flavored item with details.
|
139 |
</p>
|
140 |
</div>""")
|
|
|
141 |
|
142 |
|
|
|
|
|
143 |
gr.HTML(""" <div id="inner"> <header>
|
144 |
<h2><b>First:</b> Build a Card Template</h2>
|
145 |
</div>""")
|
146 |
with gr.Row():
|
|
|
147 |
with gr.Column():
|
|
|
|
|
148 |
|
149 |
# Template Gallery instructions
|
150 |
+
gr.HTML(""" <div id="inner"> <header>
|
151 |
+
<h3>1. Click a border from the 'Card Template Gallery'</h3>
|
152 |
+
</div>""")
|
153 |
|
154 |
border_gallery = gr.Gallery(label = "Card Template Gallery",
|
155 |
scale = 2,
|
|
|
156 |
value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/card_templates"),
|
|
|
|
|
|
|
157 |
show_label = True,
|
158 |
columns = [3], rows = [3],
|
159 |
object_fit = "contain",
|
160 |
height = "auto",
|
161 |
elem_id = "Template Gallery")
|
|
|
162 |
|
163 |
gr.HTML(""" <div id="inner"> <header>
|
164 |
<h3>2. Click a image from the Seed Image Gallery</h3><br>
|
|
|
168 |
seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
|
169 |
scale = 2,
|
170 |
value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/item_seeds"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
show_label = True,
|
172 |
columns = [3], rows = [3],
|
173 |
object_fit = "contain",
|
174 |
height = "auto",
|
175 |
elem_id = "Template Gallery",
|
|
|
176 |
interactive=True)
|
|
|
|
|
|
|
|
|
177 |
|
178 |
gr.HTML(""" <div id="inner"> <header><h4> -Or- Upload your own seed image, by dropping it into the 'Generated Template Gallery' </h4><br>
|
179 |
<h3>3. Click 'Generate Card Template'</h3><br>
|
180 |
</div>""")
|
|
|
|
|
|
|
|
|
181 |
|
182 |
built_template_gallery = gr.Gallery(label= "Generated Template Gallery",
|
183 |
scale = 1,
|
|
|
191 |
|
192 |
seed_image_gallery.select(assign_img_path, outputs = selected_seed_image)
|
193 |
built_template_gallery.upload(u.receive_upload, inputs=built_template_gallery, outputs= selected_seed_image)
|
|
|
|
|
|
|
|
|
194 |
build_card_template_button = gr.Button(value = "Generate Card Template")
|
195 |
build_card_template_button.click(build_template, inputs = [selected_border_image, selected_seed_image], outputs = [built_template_gallery, built_template])
|
196 |
|
|
|
201 |
<h3>1. Use a few words to describe the item then click 'Generate Text' </h3>
|
202 |
</div>""")
|
203 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
204 |
user_input = gr.Textbox(label = 'Item', lines =1, placeholder= "Flaming Magical Sword", elem_id= "Item", scale =4)
|
205 |
item_text_generate = gr.Button(value = "Generate item text", scale=1)
|
206 |
|
|
|
208 |
<h3> 2. Review and Edit the text</h3>
|
209 |
</div>""")
|
210 |
with gr.Row():
|
|
|
211 |
|
212 |
# Build text boxes for the broken up item dictionary values
|
213 |
|
214 |
# Build text boxes for the broken up item dictionary values
|
215 |
with gr.Column(scale = 1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
item_name_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Name'),label = 'Name', lines = 1, interactive=True, elem_id='Item Name')
|
217 |
item_type_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Type'),label = 'Type', lines = 1, interactive=True, elem_id='Item Type')
|
218 |
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')
|
|
|
225 |
item_description_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Description'),label = 'Description', lines = 1, interactive=True, elem_id='Item Description')
|
226 |
item_quote_output = gr.Textbox(value = set_textbox_defaults(textbox_default_dict, 'Quote'),label = 'Quote', lines = 1, interactive=True, elem_id='Item quote')
|
227 |
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')
|
|
|
228 |
|
229 |
|
|
|
|
|
230 |
gr.HTML(""" <div id="inner"> <header>
|
231 |
<h3> 3. This text will be used to generate the card's image.</h3>
|
232 |
</div>""")
|
|
|
255 |
)
|
256 |
generate_final_item_card = gr.Button(value = "Add Text", elem_id = "Generate user card")
|
257 |
|
|
|
258 |
|
|
|
|
|
|
|
259 |
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)
|
260 |
generate_gallery.select(assign_img_path, outputs = selected_generated_image)
|
261 |
|
|
|
283 |
item_sd_prompt_var,
|
284 |
item_sd_prompt_output])
|
285 |
|
|
|
286 |
|
|
|
|
|
|
|
|
|
287 |
generate_final_item_card.click(card.render_text_on_card, inputs = [selected_generated_image,
|
288 |
item_name_output,
|
289 |
item_type_output,
|
|
|
297 |
],
|
298 |
outputs = generate_gallery )
|
299 |
|
|
|
300 |
|
|
|
|
|
|
|
|
|
301 |
if __name__ == '__main__':
|
302 |
demo.launch(server_name = "0.0.0.0", server_port = 8000, share = False, allowed_paths = ["/media/drakosfire/Shared/","/media/drakosfire/Shared/MerchantBot/card_templates"])
|
303 |
|
user_input.py
CHANGED
@@ -5,17 +5,13 @@ import utilities as u
|
|
5 |
import sys
|
6 |
import tempfile
|
7 |
from PIL import Image
|
8 |
-
<<<<<<< HEAD
|
9 |
from github import Github
|
10 |
-
=======
|
11 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
12 |
|
13 |
image_path = str
|
14 |
end_phrase = """<|end_of_turn|>"""
|
15 |
# Indexing the contents of Card templates and temp images
|
16 |
card_template_path = "./card_templates/"
|
17 |
temp_image_path = "./image_temp"
|
18 |
-
<<<<<<< HEAD
|
19 |
|
20 |
def index_image_paths(repo_name,directory_path):
|
21 |
g = Github() # No token needed for public repos
|
@@ -28,17 +24,6 @@ def index_image_paths(repo_name,directory_path):
|
|
28 |
files.append(content_file.download_url) # Or content_file.path for just the path
|
29 |
|
30 |
return files
|
31 |
-
=======
|
32 |
-
def index_image_paths(directory_path, github_path):
|
33 |
-
list_temp_files = []
|
34 |
-
list_of_image_paths = u.directory_contents(directory_path)
|
35 |
-
for image_path in list_of_image_paths:
|
36 |
-
image_path = f"https://raw.githubusercontent.com/Drakosfire/CardGenerator/alpha-templates/seed_images/{github_path}{image_path}"
|
37 |
-
print(image_path)
|
38 |
-
list_temp_files.append(image_path)
|
39 |
-
return list_temp_files
|
40 |
-
|
41 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
42 |
|
43 |
user_pick_template_prompt = "Pick a template number from this list : "
|
44 |
user_pick_image_prompt = "Select an image : "
|
@@ -79,10 +64,7 @@ def call_llm(user_input):
|
|
79 |
response = response
|
80 |
|
81 |
response = response.replace("GPT4 Assistant: ", "")
|
82 |
-
<<<<<<< HEAD
|
83 |
print(response)
|
84 |
-
=======
|
85 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
86 |
response = igen.convert_to_dict(response)
|
87 |
if not response:
|
88 |
response = call_llm(user_input)
|
@@ -99,10 +81,7 @@ def prompt_user_input():
|
|
99 |
mimic = True
|
100 |
|
101 |
#user_input_template = input(f"Pick a template number from this list : {process_list_for_user_response(list_of_card_templates)}")
|
102 |
-
<<<<<<< HEAD
|
103 |
|
104 |
-
=======
|
105 |
-
>>>>>>> 9a956dd (Polished and launch to Hugging Face)
|
106 |
user_input_template = user_pick_item(user_pick_template_prompt,list_of_card_templates)
|
107 |
response = call_llm(user_input_item)
|
108 |
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
|
|
|
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 : "
|
|
|
64 |
response = response
|
65 |
|
66 |
response = response.replace("GPT4 Assistant: ", "")
|
|
|
67 |
print(response)
|
|
|
|
|
68 |
response = igen.convert_to_dict(response)
|
69 |
if not response:
|
70 |
response = call_llm(user_input)
|
|
|
81 |
mimic = True
|
82 |
|
83 |
#user_input_template = input(f"Pick a template number from this list : {process_list_for_user_response(list_of_card_templates)}")
|
|
|
84 |
|
|
|
|
|
85 |
user_input_template = user_pick_item(user_pick_template_prompt,list_of_card_templates)
|
86 |
response = call_llm(user_input_item)
|
87 |
print(response[u.keys_list(response,0)])
|