Spaces:
Running
Running
johnslegers
commited on
Commit
•
abfb62f
1
Parent(s):
0f4f364
fix
Browse files- modules/app.py +11 -11
modules/app.py
CHANGED
@@ -34,7 +34,7 @@ outpath = os.path.join(os.path.expanduser("~"), OUTPUT_DIRNAME)
|
|
34 |
# don't show access log entries for URLs that start with the given prefix
|
35 |
ACCESS_LOG_SUPPRESS_PATH_PREFIXES = ['/ping', '/modifier-thumbnails']
|
36 |
|
37 |
-
app.mount('media', StaticFiles(directory=os.path.join(SD_UI_DIR, 'media/')), name="media")
|
38 |
|
39 |
# defaults from https://huggingface.co/blog/stable_diffusion
|
40 |
class ImageRequest(BaseModel):
|
@@ -68,12 +68,12 @@ class ImageRequest(BaseModel):
|
|
68 |
class SetAppConfigRequest(BaseModel):
|
69 |
update_branch: str = "main"
|
70 |
|
71 |
-
@app.get('')
|
72 |
def read_root():
|
73 |
headers = {"Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0"}
|
74 |
return FileResponse(os.path.join(SD_UI_DIR, 'index.html'), headers=headers)
|
75 |
|
76 |
-
@app.get('ping')
|
77 |
async def ping():
|
78 |
global model_loaded, model_is_loading
|
79 |
|
@@ -138,7 +138,7 @@ def save_model_to_config(model_name):
|
|
138 |
|
139 |
setConfig(config)
|
140 |
|
141 |
-
@app.post('image')
|
142 |
def image(req : ImageRequest):
|
143 |
import runtime
|
144 |
|
@@ -192,7 +192,7 @@ def image(req : ImageRequest):
|
|
192 |
print(traceback.format_exc())
|
193 |
return HTTPException(status_code=500, detail=str(e))
|
194 |
|
195 |
-
@app.get('image/stop')
|
196 |
def stop():
|
197 |
try:
|
198 |
if model_is_loading:
|
@@ -206,14 +206,14 @@ def stop():
|
|
206 |
print(traceback.format_exc())
|
207 |
return HTTPException(status_code=500, detail=str(e))
|
208 |
|
209 |
-
@app.get('image/tmp/{session_id}/{img_id}')
|
210 |
def get_image(session_id, img_id):
|
211 |
import runtime
|
212 |
buf = runtime.temp_images[session_id + '/' + img_id]
|
213 |
buf.seek(0)
|
214 |
return StreamingResponse(buf, media_type='image/jpeg')
|
215 |
|
216 |
-
@app.post('app_config')
|
217 |
async def setAppConfig(req : SetAppConfigRequest):
|
218 |
try:
|
219 |
config = {
|
@@ -242,7 +242,7 @@ async def setAppConfig(req : SetAppConfigRequest):
|
|
242 |
print(traceback.format_exc())
|
243 |
return HTTPException(status_code=500, detail=str(e))
|
244 |
|
245 |
-
@app.get('app_config')
|
246 |
def getAppConfig():
|
247 |
try:
|
248 |
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
|
@@ -277,7 +277,7 @@ def setConfig(config):
|
|
277 |
except:
|
278 |
print(traceback.format_exc())
|
279 |
|
280 |
-
@app.get('models')
|
281 |
def getModels():
|
282 |
models = {
|
283 |
'active': {
|
@@ -307,12 +307,12 @@ def getModels():
|
|
307 |
|
308 |
return models
|
309 |
|
310 |
-
@app.get('modifiers.json')
|
311 |
def read_modifiers():
|
312 |
headers = {"Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0"}
|
313 |
return FileResponse(os.path.join(SD_UI_DIR, 'modifiers.json'), headers=headers)
|
314 |
|
315 |
-
@app.get('output_dir')
|
316 |
def read_home_dir():
|
317 |
return {outpath}
|
318 |
|
|
|
34 |
# don't show access log entries for URLs that start with the given prefix
|
35 |
ACCESS_LOG_SUPPRESS_PATH_PREFIXES = ['/ping', '/modifier-thumbnails']
|
36 |
|
37 |
+
app.mount('/media', StaticFiles(directory=os.path.join(SD_UI_DIR, 'media/')), name="media")
|
38 |
|
39 |
# defaults from https://huggingface.co/blog/stable_diffusion
|
40 |
class ImageRequest(BaseModel):
|
|
|
68 |
class SetAppConfigRequest(BaseModel):
|
69 |
update_branch: str = "main"
|
70 |
|
71 |
+
@app.get('/')
|
72 |
def read_root():
|
73 |
headers = {"Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0"}
|
74 |
return FileResponse(os.path.join(SD_UI_DIR, 'index.html'), headers=headers)
|
75 |
|
76 |
+
@app.get('/ping')
|
77 |
async def ping():
|
78 |
global model_loaded, model_is_loading
|
79 |
|
|
|
138 |
|
139 |
setConfig(config)
|
140 |
|
141 |
+
@app.post('/image')
|
142 |
def image(req : ImageRequest):
|
143 |
import runtime
|
144 |
|
|
|
192 |
print(traceback.format_exc())
|
193 |
return HTTPException(status_code=500, detail=str(e))
|
194 |
|
195 |
+
@app.get('/image/stop')
|
196 |
def stop():
|
197 |
try:
|
198 |
if model_is_loading:
|
|
|
206 |
print(traceback.format_exc())
|
207 |
return HTTPException(status_code=500, detail=str(e))
|
208 |
|
209 |
+
@app.get('/image/tmp/{session_id}/{img_id}')
|
210 |
def get_image(session_id, img_id):
|
211 |
import runtime
|
212 |
buf = runtime.temp_images[session_id + '/' + img_id]
|
213 |
buf.seek(0)
|
214 |
return StreamingResponse(buf, media_type='image/jpeg')
|
215 |
|
216 |
+
@app.post('/app_config')
|
217 |
async def setAppConfig(req : SetAppConfigRequest):
|
218 |
try:
|
219 |
config = {
|
|
|
242 |
print(traceback.format_exc())
|
243 |
return HTTPException(status_code=500, detail=str(e))
|
244 |
|
245 |
+
@app.get('/app_config')
|
246 |
def getAppConfig():
|
247 |
try:
|
248 |
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
|
|
|
277 |
except:
|
278 |
print(traceback.format_exc())
|
279 |
|
280 |
+
@app.get('/models')
|
281 |
def getModels():
|
282 |
models = {
|
283 |
'active': {
|
|
|
307 |
|
308 |
return models
|
309 |
|
310 |
+
@app.get('/modifiers.json')
|
311 |
def read_modifiers():
|
312 |
headers = {"Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0"}
|
313 |
return FileResponse(os.path.join(SD_UI_DIR, 'modifiers.json'), headers=headers)
|
314 |
|
315 |
+
@app.get('/output_dir')
|
316 |
def read_home_dir():
|
317 |
return {outpath}
|
318 |
|