drakosfire commited on
Commit
1c64a07
1 Parent(s): 3b509c3

to fix pathing issue to card_part pointing to github urls

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
 
app.py CHANGED
@@ -154,7 +154,7 @@ with gr.Blocks() as demo:
154
 
155
  border_gallery = gr.Gallery(label = "Card Template Gallery",
156
  scale = 2,
157
- value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/card_templates"),
158
  show_label = True,
159
  columns = [3], rows = [3],
160
  object_fit = "contain",
@@ -168,7 +168,7 @@ with gr.Blocks() as demo:
168
  border_gallery.select(assign_img_path, outputs = selected_border_image)
169
  seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
170
  scale = 2,
171
- value = useri.index_image_paths("Drakosfire/CardGenerator", "seed_images/item_seeds"),
172
  show_label = True,
173
  columns = [3], rows = [3],
174
  object_fit = "contain",
 
154
 
155
  border_gallery = gr.Gallery(label = "Card Template Gallery",
156
  scale = 2,
157
+ value = u.index_image_paths("Drakosfire/CardGenerator", "seed_images/card_templates"),
158
  show_label = True,
159
  columns = [3], rows = [3],
160
  object_fit = "contain",
 
168
  border_gallery.select(assign_img_path, outputs = selected_border_image)
169
  seed_image_gallery = gr.Gallery(label= " Image Seed Gallery",
170
  scale = 2,
171
+ value = u.index_image_paths("Drakosfire/CardGenerator", "seed_images/item_seeds"),
172
  show_label = True,
173
  columns = [3], rows = [3],
174
  object_fit = "contain",
card_generator.py CHANGED
@@ -2,8 +2,7 @@ import render_card_text as rend
2
  from PIL import Image, ImageFilter
3
  import utilities as u
4
  import ast
5
- import os
6
-
7
 
8
  def save_image(image,item_key):
9
  image.save(f"{item_key['Name']}.png")
@@ -13,28 +12,16 @@ def save_image(image,item_key):
13
  #shop_inventory = inv.inventory
14
  #purchased_item_key = shop_inventory['Shortsword']
15
  #border_path = './card_templates/Shining Sunset Border.png'
16
- base_dir = os.path.dirname(os.path.abspath(__file__))
17
- value_overlay_path = os.path.join(base_dir, "card_parts/Value_box_transparent.png")
18
  test_item = {'Name': 'Pustulent Raspberry', 'Type': 'Fruit', 'Value': '1 cp', 'Properties': ['Unusual Appearance', 'Rare Taste'], 'Weight': '0.2 lb', 'Description': 'This small fruit has a pustulent appearance, with bumps and irregular shapes covering its surface. Its vibrant colors and strange texture make it an oddity among other fruits.', 'Quote': 'A fruit that defies expectations, as sweet and sour as life itself.', 'SD Prompt': 'A small fruit with vibrant colors and irregular shapes, bumps covering its surface.'}
19
- sticker_path_dictionary = {'Default': os.path.join(base_dir, "card_parts/Sizzek Sticker.png"),
20
- 'Common': os.path.join(base_dir, "card_parts/card_parts/Common.png"),
21
- 'Uncommon': os.path.join(base_dir, "card_parts/card_parts/Uncommon.png"),
22
- 'Rare': os.path.join(base_dir, "card_parts/Rare.png"),
23
- 'Very Rare':os.path.join(base_dir, "card_parts/card_parts/card_parts/Very Rare.png"),
24
- 'Legendary':os.path.join(base_dir, "card_parts/Legendary.png")}
25
-
26
-
27
- def print_directory_structure(startpath):
28
- for root, dirs, files in os.walk(startpath):
29
- level = root.replace(startpath, '').count(os.sep)
30
- indent = ' ' * 4 * (level)
31
- print(f"{indent}{os.path.basename(root)}/")
32
- subindent = ' ' * 4 * (level + 1)
33
- for f in files:
34
- print(f"{subindent}{f}")
35
- base_dir = os.path.dirname(os.path.abspath(__file__))
36
- print("Base Directory:", base_dir)
37
- print_directory_structure(base_dir)
38
 
39
  # Function that takes in an image url and a dictionary and uses the values to print onto a card.
40
  def paste_image_and_resize(base_image,sticker_path, x_position, y_position,img_width, img_height, purchased_item_key = None):
@@ -46,7 +33,8 @@ def paste_image_and_resize(base_image,sticker_path, x_position, y_position,img_w
46
  else: sticker_path = sticker_path['Default']
47
 
48
  # Load the image to paste
49
- image_to_paste = Image.open(sticker_path)
 
50
 
51
  # Define the new size (scale) for the image you're pasting
52
 
@@ -116,6 +104,7 @@ def render_text_on_card(image_path, item_name,
116
  image = rend.render_text_with_dynamic_spacing(image, item_name, title_center_position, title_area_width, title_area_height,font_path,initial_font_size)
117
  image = rend.render_text_with_dynamic_spacing(image,type_text , type_center_position, type_area_width, type_area_height,font_path,initial_font_size)
118
  image = rend.render_text_with_dynamic_spacing(image, item_description + '\n\n' + item_properties, description_position, description_area_width, description_area_height,font_path,initial_font_size, description = True)
 
119
  paste_image_and_resize(image, value_overlay_path,x_position= 0,y_position=0, img_width= 768, img_height= 1024)
120
  image = rend.render_text_with_dynamic_spacing(image, item_value, value_position, value_area_width, value_area_height,font_path,initial_font_size)
121
  image = rend.render_text_with_dynamic_spacing(image, item_quote, quote_position, quote_area_width, quote_area_height,italics_font_path,initial_font_size, quote = True)
 
2
  from PIL import Image, ImageFilter
3
  import utilities as u
4
  import ast
5
+ from urllib.request import urlopen
 
6
 
7
  def save_image(image,item_key):
8
  image.save(f"{item_key['Name']}.png")
 
12
  #shop_inventory = inv.inventory
13
  #purchased_item_key = shop_inventory['Shortsword']
14
  #border_path = './card_templates/Shining Sunset Border.png'
15
+ base_path = "https://media.githubusercontent.com/media/Drakosfire/CardGenerator/main/card_parts/"
16
+ value_overlay_path = f"{base_path}Value_box_transparent.png"
17
  test_item = {'Name': 'Pustulent Raspberry', 'Type': 'Fruit', 'Value': '1 cp', 'Properties': ['Unusual Appearance', 'Rare Taste'], 'Weight': '0.2 lb', 'Description': 'This small fruit has a pustulent appearance, with bumps and irregular shapes covering its surface. Its vibrant colors and strange texture make it an oddity among other fruits.', 'Quote': 'A fruit that defies expectations, as sweet and sour as life itself.', 'SD Prompt': 'A small fruit with vibrant colors and irregular shapes, bumps covering its surface.'}
18
+ sticker_path_dictionary = {'Default': f"{base_path}Sizzek Sticker.png",
19
+ 'Common': f"{base_path}Common.png",
20
+ 'Uncommon': f"{base_path}Uncommon.png",
21
+ 'Rare': f"{base_path}Rare.png",
22
+ 'Very Rare':f"{base_path}Very Rare.png",
23
+ 'Legendary':f"{base_path}Legendary.png"}
24
+
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  # Function that takes in an image url and a dictionary and uses the values to print onto a card.
27
  def paste_image_and_resize(base_image,sticker_path, x_position, y_position,img_width, img_height, purchased_item_key = None):
 
33
  else: sticker_path = sticker_path['Default']
34
 
35
  # Load the image to paste
36
+
37
+ image_to_paste = Image.open(urlopen(sticker_path))
38
 
39
  # Define the new size (scale) for the image you're pasting
40
 
 
104
  image = rend.render_text_with_dynamic_spacing(image, item_name, title_center_position, title_area_width, title_area_height,font_path,initial_font_size)
105
  image = rend.render_text_with_dynamic_spacing(image,type_text , type_center_position, type_area_width, type_area_height,font_path,initial_font_size)
106
  image = rend.render_text_with_dynamic_spacing(image, item_description + '\n\n' + item_properties, description_position, description_area_width, description_area_height,font_path,initial_font_size, description = True)
107
+ #Paste value overlay
108
  paste_image_and_resize(image, value_overlay_path,x_position= 0,y_position=0, img_width= 768, img_height= 1024)
109
  image = rend.render_text_with_dynamic_spacing(image, item_value, value_position, value_area_width, value_area_height,font_path,initial_font_size)
110
  image = rend.render_text_with_dynamic_spacing(image, item_quote, quote_position, quote_area_width, quote_area_height,italics_font_path,initial_font_size, quote = True)
user_input.py CHANGED
@@ -3,7 +3,6 @@ import img2img
3
  import card_generator as card
4
  import utilities as u
5
  import sys
6
- from github import Github
7
 
8
  image_path = str
9
  end_phrase = """<|end_of_turn|>"""
@@ -11,18 +10,7 @@ end_phrase = """<|end_of_turn|>"""
11
  card_template_path = "./card_templates/"
12
  temp_image_path = "./image_temp"
13
 
14
- def index_image_paths(repo_name,directory_path):
15
- g = Github() # No token needed for public repos
16
- repo = g.get_repo(repo_name)
17
- contents = repo.get_contents(directory_path)
18
 
19
- files = []
20
- for content_file in contents:
21
- if content_file.type == "file":
22
- media_url = content_file.download_url.replace("raw.githubusercontent.com", "media.githubusercontent.com/media")
23
- files.append(media_url) # Or content_file.path for just the path
24
-
25
- return files
26
 
27
  user_pick_template_prompt = "Pick a template number from this list : "
28
  user_pick_image_prompt = "Select an image : "
 
3
  import card_generator as card
4
  import utilities as u
5
  import sys
 
6
 
7
  image_path = str
8
  end_phrase = """<|end_of_turn|>"""
 
10
  card_template_path = "./card_templates/"
11
  temp_image_path = "./image_temp"
12
 
 
 
 
 
13
 
 
 
 
 
 
 
 
14
 
15
  user_pick_template_prompt = "Pick a template number from this list : "
16
  user_pick_image_prompt = "Select an image : "
utilities.py CHANGED
@@ -2,6 +2,8 @@ from io import BytesIO
2
  import requests
3
  import os
4
  from PIL import Image
 
 
5
 
6
  image_list = []
7
  # Utility Functions to be called from all modules
@@ -45,3 +47,16 @@ def receive_upload(image_file):
45
  print(image)
46
  return image
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import requests
3
  import os
4
  from PIL import Image
5
+ from github import Github
6
+
7
 
8
  image_list = []
9
  # Utility Functions to be called from all modules
 
47
  print(image)
48
  return image
49
 
50
+ def index_image_paths(repo_name,directory_path):
51
+ g = Github() # No token needed for public repos
52
+ repo = g.get_repo(repo_name)
53
+ contents = repo.get_contents(directory_path)
54
+
55
+ files = []
56
+ for content_file in contents:
57
+ if content_file.type == "file":
58
+ media_url = content_file.download_url.replace("raw.githubusercontent.com", "media.githubusercontent.com/media")
59
+ files.append(media_url) # Or content_file.path for just the path
60
+
61
+ return files
62
+