Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,7 @@ parsed_descriptions_queue = deque()
|
|
33 |
|
34 |
# Usage limits
|
35 |
MAX_DESCRIPTIONS = 30
|
36 |
-
MAX_IMAGES =
|
37 |
|
38 |
# Preload models and checkpoints
|
39 |
print("Preloading models and checkpoints...")
|
@@ -98,6 +98,10 @@ def parse_descriptions(text):
|
|
98 |
descriptions = [desc.strip() for desc in descriptions if len(desc.split()) >= 3]
|
99 |
return descriptions
|
100 |
|
|
|
|
|
|
|
|
|
101 |
@spaces.GPU
|
102 |
def generate_descriptions(user_prompt, seed_words_input, batch_size=100, max_iterations=1): # Set max_iterations to 1
|
103 |
descriptions = []
|
@@ -133,7 +137,7 @@ def generate_descriptions(user_prompt, seed_words_input, batch_size=100, max_ite
|
|
133 |
return list(parsed_descriptions_queue)
|
134 |
|
135 |
@spaces.GPU(duration=120)
|
136 |
-
def generate_images(parsed_descriptions, max_iterations=
|
137 |
# Limit the number of descriptions passed to the image generator to 2
|
138 |
if len(parsed_descriptions) > MAX_IMAGES:
|
139 |
parsed_descriptions = parsed_descriptions[:MAX_IMAGES]
|
@@ -146,13 +150,14 @@ def generate_images(parsed_descriptions, max_iterations=2): # Set max_iteration
|
|
146 |
|
147 |
def combined_function(user_prompt, seed_words_input):
|
148 |
parsed_descriptions = generate_descriptions(user_prompt, seed_words_input)
|
|
|
149 |
images = generate_images(parsed_descriptions)
|
150 |
-
return
|
151 |
|
152 |
if __name__ == '__main__':
|
153 |
def generate_and_display(user_prompt, seed_words_input):
|
154 |
-
|
155 |
-
return
|
156 |
|
157 |
interface = gr.Interface(
|
158 |
fn=generate_and_display,
|
@@ -162,4 +167,4 @@ if __name__ == '__main__':
|
|
162 |
allow_flagging='never' # Disable flagging
|
163 |
)
|
164 |
|
165 |
-
interface.launch(share=True)
|
|
|
33 |
|
34 |
# Usage limits
|
35 |
MAX_DESCRIPTIONS = 30
|
36 |
+
MAX_IMAGES = 3 # Limit to 3 images
|
37 |
|
38 |
# Preload models and checkpoints
|
39 |
print("Preloading models and checkpoints...")
|
|
|
98 |
descriptions = [desc.strip() for desc in descriptions if len(desc.split()) >= 3]
|
99 |
return descriptions
|
100 |
|
101 |
+
def format_descriptions(descriptions):
|
102 |
+
formatted_descriptions = "\n".join(descriptions)
|
103 |
+
return formatted_descriptions
|
104 |
+
|
105 |
@spaces.GPU
|
106 |
def generate_descriptions(user_prompt, seed_words_input, batch_size=100, max_iterations=1): # Set max_iterations to 1
|
107 |
descriptions = []
|
|
|
137 |
return list(parsed_descriptions_queue)
|
138 |
|
139 |
@spaces.GPU(duration=120)
|
140 |
+
def generate_images(parsed_descriptions, max_iterations=3): # Set max_iterations to 3
|
141 |
# Limit the number of descriptions passed to the image generator to 2
|
142 |
if len(parsed_descriptions) > MAX_IMAGES:
|
143 |
parsed_descriptions = parsed_descriptions[:MAX_IMAGES]
|
|
|
150 |
|
151 |
def combined_function(user_prompt, seed_words_input):
|
152 |
parsed_descriptions = generate_descriptions(user_prompt, seed_words_input)
|
153 |
+
formatted_descriptions = format_descriptions(parsed_descriptions)
|
154 |
images = generate_images(parsed_descriptions)
|
155 |
+
return formatted_descriptions, images
|
156 |
|
157 |
if __name__ == '__main__':
|
158 |
def generate_and_display(user_prompt, seed_words_input):
|
159 |
+
formatted_descriptions, images = combined_function(user_prompt, seed_words_input)
|
160 |
+
return formatted_descriptions, images
|
161 |
|
162 |
interface = gr.Interface(
|
163 |
fn=generate_and_display,
|
|
|
167 |
allow_flagging='never' # Disable flagging
|
168 |
)
|
169 |
|
170 |
+
interface.launch(share=True)
|