Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import io
|
|
8 |
|
9 |
# Define categories at the top so they are accessible throughout the code
|
10 |
categories = [
|
11 |
-
('
|
12 |
('Position', 'position_tags'),
|
13 |
('Outfit', 'outfit_tags'),
|
14 |
('Camera View/Angle', 'camera_tags'),
|
@@ -20,18 +20,20 @@ categories = [
|
|
20 |
]
|
21 |
|
22 |
class DataManager:
|
23 |
-
def __init__(self,
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
self.
|
30 |
-
self.
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
35 |
|
36 |
self.load_data()
|
37 |
|
@@ -100,7 +102,8 @@ class DataManager:
|
|
100 |
def add_character(self, character):
|
101 |
# Save image to disk and store the filename
|
102 |
image_data = character['image'] # This is base64 encoded string
|
103 |
-
|
|
|
104 |
image_path = os.path.join(self.images_folder, image_filename)
|
105 |
|
106 |
# Decode the base64 image data and save it
|
@@ -361,7 +364,7 @@ def tags_app(data_manager):
|
|
361 |
save_persistent_tags_button.click(save_persistent_tags, inputs=persistent_tags_input, outputs=persistent_status_output)
|
362 |
|
363 |
def main():
|
364 |
-
data_manager = DataManager()
|
365 |
with gr.Blocks() as demo:
|
366 |
prompt_generator_app(data_manager)
|
367 |
character_creation_app(data_manager)
|
|
|
8 |
|
9 |
# Define categories at the top so they are accessible throughout the code
|
10 |
categories = [
|
11 |
+
('Setting', 'scene_tags'),
|
12 |
('Position', 'position_tags'),
|
13 |
('Outfit', 'outfit_tags'),
|
14 |
('Camera View/Angle', 'camera_tags'),
|
|
|
20 |
]
|
21 |
|
22 |
class DataManager:
|
23 |
+
def __init__(self, base_dir='/persistent'):
|
24 |
+
self.base_dir = base_dir
|
25 |
+
# Ensure the base directory exists
|
26 |
+
if not os.path.exists(self.base_dir):
|
27 |
+
os.makedirs(self.base_dir)
|
28 |
+
|
29 |
+
self.characters_file = os.path.join(self.base_dir, 'characters.json')
|
30 |
+
self.persistent_tags_file = os.path.join(self.base_dir, 'persistent_tags.json')
|
31 |
+
self.category_tags_file = os.path.join(self.base_dir, 'category_tags.json')
|
32 |
+
self.images_folder = os.path.join(self.base_dir, 'character_images')
|
33 |
+
|
34 |
+
# Ensure the images folder exists
|
35 |
+
if not os.path.exists(self.images_folder):
|
36 |
+
os.makedirs(self.images_folder)
|
37 |
|
38 |
self.load_data()
|
39 |
|
|
|
102 |
def add_character(self, character):
|
103 |
# Save image to disk and store the filename
|
104 |
image_data = character['image'] # This is base64 encoded string
|
105 |
+
safe_name = "".join(c for c in character['name'] if c.isalnum() or c in (' ', '_', '-')).rstrip()
|
106 |
+
image_filename = f"{safe_name}.png"
|
107 |
image_path = os.path.join(self.images_folder, image_filename)
|
108 |
|
109 |
# Decode the base64 image data and save it
|
|
|
364 |
save_persistent_tags_button.click(save_persistent_tags, inputs=persistent_tags_input, outputs=persistent_status_output)
|
365 |
|
366 |
def main():
|
367 |
+
data_manager = DataManager(base_dir='/persistent')
|
368 |
with gr.Blocks() as demo:
|
369 |
prompt_generator_app(data_manager)
|
370 |
character_creation_app(data_manager)
|