Andre commited on
Commit
3cf54d2
·
1 Parent(s): 1be71b6
.DS_Store ADDED
Binary file (6.15 kB). View file
 
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ images/
2
+ .venv/
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ from config.config import models, prompts, api_token # Direct import
3
+ import gradio as gr
4
+ from src.img_gen import generate_image
5
+
6
+ # Gradio Interface
7
+ def gradio_interface():
8
+ with gr.Blocks(css="""
9
+
10
+ .gradio-container {
11
+ background-image: url('');
12
+ background-size: cover;
13
+ background-position: center;
14
+
15
+ }
16
+
17
+ .output-image img {
18
+ width: 2500px; /* Force image to fill container width */
19
+ object-fit: cover; /* ACTIVATE FOR IMAGE-FIT CONTAINER */
20
+ }
21
+ """) as demo:
22
+ gr.Markdown("# ========== Loot Survivor - AI Image Generator ==========")
23
+ with gr.Row():
24
+ # Set default values for dropdowns
25
+ prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Prompt", value=prompts[0]["alias"])
26
+ character_dropdown = gr.Dropdown(choices=["Beast only", "Wizard", "Warrior"], label="Select Character", value="Beast only")
27
+ model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models], label="Select Model", value=models[0]["alias"])
28
+ with gr.Row():
29
+ # Add a text box for custom user input (max 200 characters)
30
+ custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
31
+ with gr.Row():
32
+ generate_button = gr.Button("Generate Image")
33
+ with gr.Row():
34
+ output_image = gr.Image(elem_classes="output-image", label="Generated Image", show_label=False, scale=1, width="100%")
35
+ with gr.Row():
36
+ status_text = gr.Textbox(label="Status", placeholder="Waiting for input...", interactive=False)
37
+
38
+ # Connect the button to the function
39
+ generate_button.click(
40
+ generate_image,
41
+ inputs=[prompt_dropdown,
42
+ custom_prompt_input,
43
+ character_dropdown,
44
+ model_dropdown
45
+ ],
46
+ outputs=[output_image, status_text]
47
+ )
48
+ return demo
49
+
50
+ # Create the demo instance
51
+ demo = gradio_interface()
52
+
53
+ # Only launch if running directly
54
+ if __name__ == "__main__":
55
+ demo.queue().launch()
config/__pycache__/config.cpython-311.pyc ADDED
Binary file (947 Bytes). View file
 
config/__pycache__/models.cpython-311.pyc ADDED
Binary file (332 Bytes). View file
 
config/__pycache__/prompts.cpython-311.pyc ADDED
Binary file (2.94 kB). View file
 
config/config.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # config.py
2
+ import os
3
+ from config.prompts import prompts
4
+ from config.models import models
5
+
6
+ # Retrieve the Hugging Face token
7
+ api_token = os.getenv("HF_TOKEN")
8
+
9
+ # Debugging: Print prompt and model options
10
+ print("##### IMPORTING CONFIG #####")
11
+ print("Prompt Options:", [p["alias"] for p in prompts])
12
+ print("Model Options:", [m["alias"] for m in models])
config/models.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # List of models with aliases
2
+ models = [
3
+ {"alias": "FLUX.1-dev", "name": "black-forest-labs/FLUX.1-dev"},
4
+ {"alias": "Midjourney", "name": "strangerzonehf/Flux-Midjourney-Mix2-LoRA"},
5
+ ]
config/prompts.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # List of prompts with intense combat
3
+ #
4
+
5
+ prompts = [
6
+ {
7
+ "alias": "Mantis",
8
+ "text": "A towering, predatory mantis with razor-sharp scythe-like arms, covered in chitinous armor with a metallic green sheen. Its eyes glow faintly in the dark, and its mandibles drip with venom. Unreal Engine render style, photorealistic, realistic fantasy style."
9
+ },
10
+ {
11
+ "alias": "Spider",
12
+ "text": "A massive, hairy spider with glowing red eyes and fangs dripping with poison. Its legs are covered in sharp spines, and its body is adorned with intricate, web-like patterns. It lurks in the shadows of a damp, moss-covered environment. Unreal Engine render style, photorealistic, realistic fantasy style."
13
+ },
14
+ {
15
+ "alias": "Pixie",
16
+ "text": "A tiny, mischievous pixie with translucent wings shimmering like stained glass. Its glowing blue eyes and pointed ears give it an otherworldly appearance. It hovers in the air, surrounded by a faint magical aura. Unreal Engine render style, photorealistic, realistic fantasy style."
17
+ },
18
+ {
19
+ "alias": "Wolf",
20
+ "text": "A ferocious, oversized wolf with matted fur, glowing yellow eyes, and saliva dripping from its sharp fangs. Its muscular frame is scarred from battles, and it snarls menacingly in the torchlight. Unreal Engine render style, photorealistic, realistic fantasy style."
21
+ },
22
+ {
23
+ "alias": "Rat",
24
+ "text": "A giant, diseased rat with matted fur, glowing red eyes, and long, jagged claws. Its tail is thick and scaly, and it crouches in a filthy, garbage-strewn corner. Unreal Engine render style, photorealistic, realistic fantasy style."
25
+ },
26
+ {
27
+ "alias": "Ogre",
28
+ "text": "A hulking ogre with greenish-gray skin, covered in warts and scars. Its massive fists are clenched, and it wears crude armor made of bones and leather. It roars menacingly, surrounded by broken weapons and bones. Unreal Engine render style, photorealistic, realistic fantasy style."
29
+ },
30
+ {
31
+ "alias": "Troll",
32
+ "text": "A towering troll with rocky, moss-covered skin and glowing orange eyes. Its long arms end in clawed hands, and it wields a massive wooden club. It stands in a damp, torchlit environment, surrounded by rubble. Unreal Engine render style, photorealistic, realistic fantasy style."
33
+ },
34
+ {
35
+ "alias": "Bigfoot",
36
+ "text": "A massive, ape-like creature with thick, matted fur and glowing yellow eyes. Its muscular frame is covered in scars, and it roars menacingly in a dark, forested area. Unreal Engine render style, photorealistic, realistic fantasy style."
37
+ },
38
+ {
39
+ "alias": "Bear",
40
+ "text": "A monstrous bear with matted fur, glowing red eyes, and sharp, bloodstained claws. Its massive frame is covered in scars, and it roars fiercely, surrounded by bones and broken weapons. Unreal Engine render style, photorealistic, realistic fantasy style."
41
+ }
42
+ ]
43
+
config/prompts_no_tooMuchDungeon.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ prompts = [
2
+ {
3
+ "alias": "Mantis",
4
+ "text": "A towering, predatory mantis with razor-sharp scythe-like arms, covered in chitinous armor with a metallic green sheen. Its eyes glow faintly in the dark dungeon, and its mandibles drip with venom. The creature stands amidst crumbling stone walls and scattered bones. Unreal Engine render style, photorealistic, realistic fantasy style"
5
+ },
6
+ {
7
+ "alias": "Spider",
8
+ "text": "A massive, hairy spider with glowing red eyes and fangs dripping with poison. Its legs are covered in sharp spines, and its body is adorned with intricate, web-like patterns. It lurks in the shadows of a damp, moss-covered dungeon corridor, surrounded by ancient stone pillars. Unreal Engine render style, photorealistic, realistic fantasy style"
9
+ },
10
+ {
11
+ "alias": "Pixie",
12
+ "text": "A tiny, mischievous pixie with translucent wings shimmering like stained glass. Its glowing blue eyes and pointed ears give it an otherworldly appearance. It hovers in the air, surrounded by a faint magical aura, within a dimly lit dungeon chamber filled with glowing runes. Unreal Engine render style, photorealistic, realistic fantasy style"
13
+ },
14
+ {
15
+ "alias": "Wolf",
16
+ "text": "A ferocious, oversized wolf with matted fur, glowing yellow eyes, and saliva dripping from its sharp fangs. Its muscular frame is scarred from battles, and it snarls menacingly in the torchlight of a narrow dungeon passage, surrounded by broken chains and debris. Unreal Engine render style, photorealistic, realistic fantasy style"
17
+ },
18
+ {
19
+ "alias": "Rat",
20
+ "text": "A giant, diseased rat with matted fur, glowing red eyes, and long, jagged claws. Its tail is thick and scaly, and it crouches in a filthy, garbage-strewn corner of a dungeon, surrounded by rotting wood and rusted metal. Unreal Engine render style, photorealistic, realistic fantasy style"
21
+ },
22
+ {
23
+ "alias": "Ogre",
24
+ "text": "A hulking ogre with greenish-gray skin, covered in warts and scars. Its massive fists are clenched, and it wears crude armor made of bones and leather. It roars menacingly in a torchlit dungeon chamber, surrounded by broken weapons, bones, and shattered stone. Unreal Engine render style, photorealistic, realistic fantasy style"
25
+ },
26
+ {
27
+ "alias": "Troll",
28
+ "text": "A towering troll with rocky, moss-covered skin and glowing orange eyes. Its long arms end in clawed hands, and it wields a massive wooden club. It stands in a damp, torchlit dungeon hall, surrounded by rubble and ancient carvings on the walls. Unreal Engine render style, photorealistic, realistic fantasy style"
29
+ },
30
+ {
31
+ "alias": "Bigfoot",
32
+ "text": "A massive, ape-like creature with thick, matted fur and glowing yellow eyes. Its muscular frame is covered in scars, and it roars menacingly in a dark, forested section of the dungeon, where roots and vines have broken through the stone walls. Unreal Engine render style, photorealistic, realistic fantasy style"
33
+ },
34
+ {
35
+ "alias": "Bear",
36
+ "text": "A monstrous bear with matted fur, glowing red eyes, and sharp, bloodstained claws. Its massive frame is covered in scars, and it roars fiercely in a torchlit dungeon chamber, surrounded by bones, broken weapons, and shattered stone. Unreal Engine render style, photorealistic, realistic fantasy style"
37
+ }
38
+ ]
early_notes/prompts.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ lets create some prompts fo img gn about some creatures. the imgs are about a game, a dungeon game, where player search for loot and try to survive, the img we will generate represent the mosters thy can find inside those dungeons. the them is medieval / fantasy. but the prompts should try to be photorealistic. i will give you a raw list of the monsters, maybe you will need the clear it up a bit, and make me the prompts on a json format w a alias and a text; please als add to the end of each prompt these: "Unreal Engine render style, photorealistic, realistic fantasy style"
2
+
3
+ monsters lis: "beasts": [
4
+ {
5
+ "beast": "Mantis"
6
+ },
7
+ {
8
+ "beast": "Spider"
9
+ },
10
+ {
11
+ "beast": "Pixie"
12
+ },
13
+ {
14
+ "beast": "Wolf"
15
+ },
16
+ {
17
+ "beast": "Rat"
18
+ },
19
+ {
20
+ "beast": "Ogre"
21
+ },
22
+ {
23
+ "beast": "Troll"
24
+ },
25
+ {
26
+ "beast": "Rat"
27
+ },
28
+ {
29
+ "beast": "Bigfoot"
30
+ },
31
+ {
32
+ "beast": "Bear"
33
+ }
34
+ ]
index.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Function to get supported image files
3
+ function getImages($directory) {
4
+ $allowedTypes = array('jpg', 'jpeg', 'png', 'gif');
5
+ $files = array();
6
+
7
+ if (is_dir($directory)) {
8
+ $dirContent = scandir($directory);
9
+ foreach ($dirContent as $file) {
10
+ $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
11
+ if (in_array($extension, $allowedTypes)) {
12
+ $files[] = $file;
13
+ }
14
+ }
15
+ }
16
+ return $files;
17
+ }
18
+ ?>
19
+
20
+ <!DOCTYPE html>
21
+ <html lang="en">
22
+ <head>
23
+ <meta charset="UTF-8">
24
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
25
+ <title>Dark Theme Image Gallery</title>
26
+ <style>
27
+ body {
28
+ background-color: #1a1a1a;
29
+ color: #ffffff;
30
+ font-family: Arial, sans-serif;
31
+ margin: 0;
32
+ padding: 20px;
33
+ }
34
+
35
+ .gallery-container {
36
+ max-width: 1200px;
37
+ margin: 0 auto;
38
+ }
39
+
40
+ h1 {
41
+ text-align: center;
42
+ color: #ffffff;
43
+ margin-bottom: 30px;
44
+ }
45
+
46
+ .gallery {
47
+ display: grid;
48
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
49
+ gap: 20px;
50
+ padding: 20px;
51
+ }
52
+
53
+ .gallery-item {
54
+ position: relative;
55
+ overflow: hidden;
56
+ border-radius: 8px;
57
+ background-color: #2d2d2d;
58
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
59
+ transition: transform 0.3s ease;
60
+ cursor: pointer;
61
+ }
62
+
63
+ .gallery-item:hover {
64
+ transform: scale(1.02);
65
+ }
66
+
67
+ .gallery-item img {
68
+ width: 100%;
69
+ height: 200px;
70
+ object-fit: cover;
71
+ display: block;
72
+ }
73
+
74
+ .image-caption {
75
+ padding: 10px;
76
+ background-color: rgba(0, 0, 0, 0.7);
77
+ color: #ffffff;
78
+ font-size: 0.9em;
79
+ text-align: center;
80
+ }
81
+
82
+ /* Lightbox styles */
83
+ .lightbox {
84
+ display: none;
85
+ position: fixed;
86
+ top: 0;
87
+ left: 0;
88
+ width: 100%;
89
+ height: 100%;
90
+ background-color: rgba(0, 0, 0, 0.9);
91
+ z-index: 1000;
92
+ justify-content: center;
93
+ align-items: center;
94
+ cursor: pointer;
95
+ }
96
+
97
+ .lightbox.active {
98
+ display: flex;
99
+ }
100
+
101
+ .lightbox img {
102
+ max-width: 90%;
103
+ max-height: 90vh;
104
+ object-fit: contain;
105
+ border: 2px solid #ffffff;
106
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
107
+ }
108
+
109
+ .close-button {
110
+ position: fixed;
111
+ top: 20px;
112
+ right: 20px;
113
+ color: #ffffff;
114
+ font-size: 30px;
115
+ cursor: pointer;
116
+ background: none;
117
+ border: none;
118
+ padding: 10px;
119
+ z-index: 1001;
120
+ }
121
+
122
+ @media (max-width: 768px) {
123
+ .gallery {
124
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
125
+ }
126
+ }
127
+ </style>
128
+ </head>
129
+ <body>
130
+ <div class="gallery-container">
131
+ <h1>========== LS-AI-img-gen - Image Gallery ==========</h1>
132
+ <div class="gallery">
133
+ <?php
134
+ // Specify your images directory
135
+ $imageDirectory = 'images/';
136
+ $images = getImages($imageDirectory);
137
+
138
+ foreach ($images as $image) {
139
+ echo '<div class="gallery-item" onclick="openLightbox(\'' . $imageDirectory . $image . '\')">';
140
+ echo '<img src="' . $imageDirectory . $image . '" alt="' . pathinfo($image, PATHINFO_FILENAME) . '">';
141
+ echo '<div class="image-caption">' . pathinfo($image, PATHINFO_FILENAME) . '</div>';
142
+ echo '</div>';
143
+ }
144
+
145
+ if (empty($images)) {
146
+ echo '<p style="text-align: center; grid-column: 1/-1;">No images found in the gallery.</p>';
147
+ }
148
+ ?>
149
+ </div>
150
+ </div>
151
+
152
+ <!-- Lightbox container -->
153
+ <div class="lightbox" id="lightbox" onclick="closeLightbox()">
154
+ <button class="close-button" onclick="closeLightbox()">&times;</button>
155
+ <img id="lightbox-img" src="" alt="Lightbox image">
156
+ </div>
157
+
158
+ <script>
159
+ function openLightbox(imageSrc) {
160
+ const lightbox = document.getElementById('lightbox');
161
+ const lightboxImg = document.getElementById('lightbox-img');
162
+ lightboxImg.src = imageSrc;
163
+ lightbox.classList.add('active');
164
+ // Prevent scrolling when lightbox is open
165
+ document.body.style.overflow = 'hidden';
166
+ }
167
+
168
+ function closeLightbox() {
169
+ const lightbox = document.getElementById('lightbox');
170
+ lightbox.classList.remove('active');
171
+ // Restore scrolling
172
+ document.body.style.overflow = 'auto';
173
+ }
174
+
175
+ // Close lightbox with Escape key
176
+ document.addEventListener('keydown', function(event) {
177
+ if (event.key === 'Escape') {
178
+ closeLightbox();
179
+ }
180
+ });
181
+
182
+ // Prevent lightbox from closing when clicking on the image
183
+ document.getElementById('lightbox-img').addEventListener('click', function(event) {
184
+ event.stopPropagation();
185
+ });
186
+ </script>
187
+ </body>
188
+ </html>
index_old.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Function to get supported image files
3
+ function getImages($directory) {
4
+ $allowedTypes = array('jpg', 'jpeg', 'png', 'gif');
5
+ $files = array();
6
+
7
+ if (is_dir($directory)) {
8
+ $dirContent = scandir($directory);
9
+ foreach ($dirContent as $file) {
10
+ $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
11
+ if (in_array($extension, $allowedTypes)) {
12
+ $files[] = $file;
13
+ }
14
+ }
15
+ }
16
+ return $files;
17
+ }
18
+ ?>
19
+
20
+ <!DOCTYPE html>
21
+ <html lang="en">
22
+ <head>
23
+ <meta charset="UTF-8">
24
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
25
+ <title>Dark Theme Image Gallery</title>
26
+ <style>
27
+ body {
28
+ background-color: #1a1a1a;
29
+ color: #ffffff;
30
+ font-family: Arial, sans-serif;
31
+ margin: 0;
32
+ padding: 20px;
33
+ }
34
+
35
+ .gallery-container {
36
+ max-width: 1200px;
37
+ margin: 0 auto;
38
+ }
39
+
40
+ h1 {
41
+ text-align: center;
42
+ color: #ffffff;
43
+ margin-bottom: 30px;
44
+ }
45
+
46
+ .gallery {
47
+ display: grid;
48
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
49
+ gap: 20px;
50
+ padding: 20px;
51
+ }
52
+
53
+ .gallery-item {
54
+ position: relative;
55
+ overflow: hidden;
56
+ border-radius: 8px;
57
+ background-color: #2d2d2d;
58
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
59
+ transition: transform 0.3s ease;
60
+ }
61
+
62
+ .gallery-item:hover {
63
+ transform: scale(1.02);
64
+ }
65
+
66
+ .gallery-item img {
67
+ width: 100%;
68
+ height: 200px;
69
+ object-fit: cover;
70
+ display: block;
71
+ }
72
+
73
+ .image-caption {
74
+ padding: 10px;
75
+ background-color: rgba(0, 0, 0, 0.7);
76
+ color: #ffffff;
77
+ font-size: 0.9em;
78
+ text-align: center;
79
+ }
80
+
81
+ @media (max-width: 768px) {
82
+ .gallery {
83
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
84
+ }
85
+ }
86
+ </style>
87
+ </head>
88
+ <body>
89
+ <div class="gallery-container">
90
+ <h1>========== LS-AI-img-gen - Image Gallery ==========</h1>
91
+ <div class="gallery">
92
+ <?php
93
+ // Specify your images directory
94
+ $imageDirectory = 'images/';
95
+ $images = getImages($imageDirectory);
96
+
97
+ foreach ($images as $image) {
98
+ echo '<div class="gallery-item">';
99
+ echo '<img src="' . $imageDirectory . $image . '" alt="' . pathinfo($image, PATHINFO_FILENAME) . '">';
100
+ echo '<div class="image-caption">' . pathinfo($image, PATHINFO_FILENAME) . '</div>';
101
+ echo '</div>';
102
+ }
103
+
104
+ if (empty($images)) {
105
+ echo '<p style="text-align: center; grid-column: 1/-1;">No images found in the gallery.</p>';
106
+ }
107
+ ?>
108
+ </div>
109
+ </div>
110
+ </body>
111
+ </html>
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ diffusers
3
+ transformers
4
+ accelerate
5
+ gradio
6
+ safetensors
7
+ pillow
8
+ numpy<2
9
+ invisible_watermark
10
+ huggingface_hub[hf_transfer]
11
+ sentencepiece
12
+ opencv-python==4.5.5.64
13
+ gguf
src/__pycache__/img_gen.cpython-311.pyc ADDED
Binary file (4.91 kB). View file
 
src/img_gen copy.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # img_gen.py
2
+ import sys
3
+ import os
4
+ import random
5
+ from huggingface_hub import InferenceClient, login
6
+ from datetime import datetime
7
+ from config.config import models, prompts, api_token # Direct import
8
+
9
+ def generate_image(
10
+ prompt_alias,
11
+ custom_prompt,
12
+ characer_dropdown,
13
+ model_alias,
14
+ height=360,
15
+ width=640,
16
+ num_inference_steps=20,
17
+ guidance_scale=2.0,
18
+ seed=-1):
19
+ # Find the selected prompt and model
20
+ try:
21
+ prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
22
+ model_name = next(m for m in models if m["alias"] == model_alias)["name"]
23
+
24
+ except StopIteration:
25
+ return None, "ERROR: Invalid prompt or model selected."
26
+
27
+ # Print the original prompt and dynamic values for debugging
28
+ print("Original Prompt:")
29
+ print(prompt)
30
+
31
+ # Append the custom character (if provided)
32
+ if characer_dropdown == "Wizard":
33
+ prompt += " A wizard dressed in tunic figths against the beast"
34
+ elif characer_dropdown == "Warrior":
35
+ prompt += " A medieval warrior in armor figths against the beast"
36
+ else:
37
+ pass
38
+
39
+ # Append the custom prompt (if provided)
40
+ if custom_prompt and len(custom_prompt.strip()) > 0:
41
+ prompt += " " + custom_prompt.strip()
42
+
43
+ # Print the formatted prompt for debugging
44
+ print("\nFormatted Prompt:")
45
+ print(prompt)
46
+
47
+ # Randomize the seed if needed
48
+ if seed == -1:
49
+ seed = random.randint(0, 1000000)
50
+
51
+ # HF LOGIN
52
+ print("Initializing HF TOKEN")
53
+ print (api_token)
54
+ # login(token=api_token)
55
+ # print("model_name:")
56
+ # print(model_name)
57
+
58
+
59
+ # Initialize the InferenceClient
60
+ try:
61
+ print("-----INITIALIZING INFERENCE-----")
62
+ client = InferenceClient(model_name, token=api_token)
63
+ print("Inference activated")
64
+ except Exception as e:
65
+ return None, f"ERROR: Failed to initialize InferenceClient. Details: {e}"
66
+
67
+ #Generate the image
68
+ try:
69
+ print("-----GENERATING IMAGE-----")
70
+ print("-----HOLD ON-----")
71
+ image = client.text_to_image(
72
+ prompt,
73
+ guidance_scale=guidance_scale,
74
+ num_inference_steps=num_inference_steps,
75
+ width=width,
76
+ height=height,
77
+ seed=seed
78
+ )
79
+ print("-----IMAGE GENERATED SUCCESSFULLY!-----")
80
+ except Exception as e:
81
+ return None, f"ERROR: Failed to generate image. Details: {e}"
82
+
83
+ # Save the image with a timestamped filename
84
+ print("-----SAVING-----", image)
85
+ path = "images"
86
+
87
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
88
+ output_filename = f"{path}/{timestamp}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}.png"
89
+ try:
90
+ image.save(output_filename)
91
+ except Exception as e:
92
+ return None, f"ERROR: Failed to save image. Details: {e}"
93
+ print("-----DONE!-----")
94
+ print("-----CALL THE BANNERS!-----")
95
+
96
+ return output_filename, "Image generated successfully!"
src/img_gen.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # img_gen.py
2
+ import sys
3
+ import os
4
+ import random
5
+ from huggingface_hub import InferenceClient, login
6
+ from datetime import datetime
7
+ from config.config import models, prompts, api_token # Direct import
8
+
9
+ def generate_image(
10
+ prompt_alias,
11
+ custom_prompt,
12
+ characer_dropdown,
13
+ model_alias,
14
+ height=360,
15
+ width=640,
16
+ num_inference_steps=20,
17
+ guidance_scale=2.0,
18
+ seed=-1):
19
+ # Find the selected prompt and model
20
+ try:
21
+ prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
22
+ model_name = next(m for m in models if m["alias"] == model_alias)["name"]
23
+
24
+ except StopIteration:
25
+ return None, "ERROR: Invalid prompt or model selected."
26
+
27
+ # Print the original prompt and dynamic values for debugging
28
+ print("Original Prompt:")
29
+ print(prompt)
30
+
31
+ # Append the custom character (if provided)
32
+ if characer_dropdown == "Wizard":
33
+ prompt += f" A fantasy wizard figths against the {prompt_alias}"
34
+ elif characer_dropdown == "Warrior":
35
+ prompt += f" A fantasy warrior figths against the {prompt_alias}"
36
+ else:
37
+ pass
38
+
39
+ # Append the custom prompt (if provided)
40
+ if custom_prompt and len(custom_prompt.strip()) > 0:
41
+ prompt += " " + custom_prompt.strip()
42
+
43
+ # Print the formatted prompt for debugging
44
+ print("\nFormatted Prompt:")
45
+ print(prompt)
46
+
47
+ # Randomize the seed if needed
48
+ if seed == -1:
49
+ seed = random.randint(0, 1000000)
50
+
51
+ # HF LOGIN
52
+ print("Initializing HF TOKEN")
53
+ print (api_token)
54
+ # login(token=api_token)
55
+ # print("model_name:")
56
+ # print(model_name)
57
+
58
+
59
+ # Initialize the InferenceClient
60
+ try:
61
+ print("-----INITIALIZING INFERENCE-----")
62
+ client = InferenceClient(model_name, token=api_token)
63
+ print("Inference activated")
64
+ except Exception as e:
65
+ return None, f"ERROR: Failed to initialize InferenceClient. Details: {e}"
66
+
67
+ #Generate the image
68
+ try:
69
+ print("-----GENERATING IMAGE-----")
70
+ print("-----HOLD ON-----")
71
+ image = client.text_to_image(
72
+ prompt,
73
+ guidance_scale=guidance_scale,
74
+ num_inference_steps=num_inference_steps,
75
+ width=width,
76
+ height=height,
77
+ seed=seed
78
+ )
79
+ print("-----IMAGE GENERATED SUCCESSFULLY!-----")
80
+ except Exception as e:
81
+ return None, f"ERROR: Failed to generate image. Details: {e}"
82
+
83
+ # Save the image with a timestamped filename
84
+ print("-----SAVING-----", image)
85
+ path = "images"
86
+
87
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
88
+ output_filename = f"{path}/{timestamp}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}.png"
89
+ try:
90
+ image.save(output_filename)
91
+ except Exception as e:
92
+ return None, f"ERROR: Failed to save image. Details: {e}"
93
+ print("-----DONE!-----")
94
+ print("-----CALL THE BANNERS!-----")
95
+
96
+ return output_filename, "Image generated successfully!"