Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -188,12 +188,6 @@ def invert_displayed_image(image):
|
|
188 |
return inverted
|
189 |
|
190 |
|
191 |
-
MAX_TOKENS = 150
|
192 |
-
|
193 |
-
def count_tokens(text):
|
194 |
-
"""Count the number of tokens in the text."""
|
195 |
-
return len(text.split())
|
196 |
-
|
197 |
@spaces.GPU()
|
198 |
def inference(
|
199 |
qr_code_content: str,
|
@@ -228,13 +222,6 @@ def inference(
|
|
228 |
if qrcode_image is None and qr_code_content == "":
|
229 |
raise gr.Error("QR Code Image or QR Code Content is required")
|
230 |
|
231 |
-
# Validate the length of the prompt
|
232 |
-
if count_tokens(prompt) > MAX_TOKENS:
|
233 |
-
raise gr.Error(f"Prompt exceeds the maximum allowed tokens of {MAX_TOKENS}")
|
234 |
-
|
235 |
-
if count_tokens(negative_prompt) > MAX_TOKENS:
|
236 |
-
raise gr.Error(f"Negative prompt exceeds the maximum allowed tokens of {MAX_TOKENS}")
|
237 |
-
|
238 |
pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
|
239 |
|
240 |
if seed == -1:
|
@@ -307,29 +294,6 @@ def inference(
|
|
307 |
print(f"Unexpected error in inference: {str(e)}")
|
308 |
return Image.new('RGB', (1024, 1024), color='white'), -1
|
309 |
|
310 |
-
|
311 |
-
|
312 |
-
def split_prompt(prompt, max_length=77):
|
313 |
-
"""Split the prompt into chunks that do not exceed the max_length."""
|
314 |
-
words = prompt.split()
|
315 |
-
chunks = []
|
316 |
-
current_chunk = []
|
317 |
-
current_length = 0
|
318 |
-
|
319 |
-
for word in words:
|
320 |
-
if current_length + len(word) + 1 > max_length:
|
321 |
-
chunks.append(" ".join(current_chunk))
|
322 |
-
current_chunk = [word]
|
323 |
-
current_length = len(word) + 1
|
324 |
-
else:
|
325 |
-
current_chunk.append(word)
|
326 |
-
current_length += len(word) + 1
|
327 |
-
|
328 |
-
if current_chunk:
|
329 |
-
chunks.append(" ".join(current_chunk))
|
330 |
-
|
331 |
-
return chunks
|
332 |
-
|
333 |
def invert_init_image_display(image):
|
334 |
if image is None:
|
335 |
return None
|
|
|
188 |
return inverted
|
189 |
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
@spaces.GPU()
|
192 |
def inference(
|
193 |
qr_code_content: str,
|
|
|
222 |
if qrcode_image is None and qr_code_content == "":
|
223 |
raise gr.Error("QR Code Image or QR Code Content is required")
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
|
226 |
|
227 |
if seed == -1:
|
|
|
294 |
print(f"Unexpected error in inference: {str(e)}")
|
295 |
return Image.new('RGB', (1024, 1024), color='white'), -1
|
296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
def invert_init_image_display(image):
|
298 |
if image is None:
|
299 |
return None
|