Skip to content

Commit f968079

Browse files
committed
randomize image names to prevent caching in noscript
1 parent 687bb53 commit f968079

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

koboldcpp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import socket
2727
import threading
2828
import html
29+
import random
2930
import urllib.parse as urlparse
3031
from concurrent.futures import ThreadPoolExecutor
3132
from datetime import datetime, timezone
@@ -1750,7 +1751,6 @@ def websearch(query):
17501751
import urllib.parse
17511752
import urllib.request
17521753
import difflib
1753-
import random
17541754
from html.parser import HTMLParser
17551755
from concurrent.futures import ThreadPoolExecutor
17561756
num_results = 3
@@ -2617,7 +2617,7 @@ def noscript_webui(self):
26172617
updated_query_string = urlparse.urlencode(parsed_dict, doseq=True)
26182618
updated_path = parsed_url._replace(query=updated_query_string).geturl()
26192619
self.path = updated_path
2620-
time.sleep(0.2) #short delay
2620+
time.sleep(0.3) #short delay
26212621
self.send_response(302)
26222622
self.send_header("location", self.path)
26232623
self.end_headers(content_type='text/html')
@@ -2631,8 +2631,9 @@ def noscript_webui(self):
26312631
bodycontent = f'''<b><u>{"Image Mode" if imgmode else ("Chat Mode" if chatmode else "Story Mode")}</u></b><br>'''
26322632
optionscontent = ""
26332633
if imgmode:
2634+
randimg = f'<img src="view_image{random.randint(100, 999)}.png" width="320" width="320">'
26342635
bodycontent += f'''<p>Generated Image: {prompt if prompt else "None"}</p>
2635-
{'<img src="view.png" width="320" width="320">' if prompt else ""}<br>
2636+
{randimg if prompt else ""}<br>
26362637
<label>Image Prompt: </label><input type="text" size="40" value="" name="imgprompt">
26372638
<input type="hidden" name="generate" value="Generate" />
26382639
<input type="submit" value="Generate"> (Be patient)'''
@@ -2834,7 +2835,7 @@ def do_GET(self):
28342835
response_body = (json.dumps([]).encode())
28352836
else:
28362837
response_body = (json.dumps([friendlysdmodelname]).encode())
2837-
elif self.path=='/view' or self.path=='/view.png' or self.path=='/api/view' or self.path.startswith('/view?') or self.path.startswith('/api/view?'): #emulate comfyui
2838+
elif self.path=='/view' or self.path=='/view.png' or self.path=='/api/view' or self.path.startswith('/view_image') or self.path.startswith('/view?') or self.path.startswith('/api/view?'): #emulate comfyui
28382839
content_type = 'image/png'
28392840
response_body = lastgeneratedcomfyimg
28402841
elif self.path=='/history' or self.path=='/api/history' or self.path.startswith('/api/history/') or self.path.startswith('/history/'): #emulate comfyui

0 commit comments

Comments
 (0)