Spaces:
Paused
Paused
back to pre browser
Browse files
app.py
CHANGED
@@ -10,7 +10,6 @@ from app.logger import setup_logger
|
|
10 |
import itertools
|
11 |
import utils.extra_config
|
12 |
import logging
|
13 |
-
import threading
|
14 |
|
15 |
if __name__ == "__main__":
|
16 |
#NOTE: These do not do anything on core ComfyUI which should already have no communication with the internet, they are for custom nodes.
|
@@ -56,8 +55,6 @@ if __name__ == "__main__":
|
|
56 |
|
57 |
setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)
|
58 |
|
59 |
-
|
60 |
-
|
61 |
def apply_custom_paths():
|
62 |
# extra model paths
|
63 |
extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
|
@@ -305,86 +302,7 @@ def start_comfyui(asyncio_loop=None):
|
|
305 |
|
306 |
cuda_malloc_warning()
|
307 |
|
308 |
-
# Inject file browser routes into the FastAPI app
|
309 |
-
# In your app.py (inside start_comfyui)
|
310 |
-
from fastapi import UploadFile, Request, Form
|
311 |
-
from fastapi.responses import HTMLResponse, FileResponse, RedirectResponse
|
312 |
-
from fastapi.routing import APIRouter
|
313 |
-
import mimetypes
|
314 |
-
|
315 |
-
UPLOAD_FOLDER = "/data"
|
316 |
-
router = APIRouter()
|
317 |
-
|
318 |
-
# Helper to get safe paths
|
319 |
-
def get_safe_path(subpath: str):
|
320 |
-
full_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, subpath))
|
321 |
-
if not full_path.startswith(os.path.abspath(UPLOAD_FOLDER)):
|
322 |
-
raise ValueError("Invalid path")
|
323 |
-
return full_path
|
324 |
-
|
325 |
-
@router.get("/files/{path:path}", response_class=HTMLResponse)
|
326 |
-
async def browse_files(path: str):
|
327 |
-
full_path = get_safe_path(path)
|
328 |
-
if not os.path.exists(full_path):
|
329 |
-
return HTMLResponse("Not found", status_code=404)
|
330 |
-
|
331 |
-
if os.path.isfile(full_path):
|
332 |
-
mime_type, _ = mimetypes.guess_type(full_path)
|
333 |
-
return FileResponse(full_path, media_type=mime_type)
|
334 |
-
|
335 |
-
# Show folder listing
|
336 |
-
files = os.listdir(full_path)
|
337 |
-
files.sort()
|
338 |
-
parent_path = os.path.dirname(path)
|
339 |
-
list_html = f'<li><a href="/files/{parent_path}">.. (Up)</a></li>' if path else ''
|
340 |
-
for f in files:
|
341 |
-
sub = os.path.join(path, f)
|
342 |
-
encoded = sub.replace(" ", "%20")
|
343 |
-
entry_path = os.path.join(full_path, f)
|
344 |
-
preview = ''
|
345 |
-
if os.path.isfile(entry_path):
|
346 |
-
mime, _ = mimetypes.guess_type(entry_path)
|
347 |
-
if mime and mime.startswith("image"):
|
348 |
-
preview = f'<br><img src="/files/{encoded}" style="max-height:100px;">'
|
349 |
-
elif mime and mime.startswith("video"):
|
350 |
-
preview = f'<br><video src="/files/{encoded}" style="max-height:100px;" controls></video>'
|
351 |
-
list_html += f'<li><a href="/files/{encoded}">{f}</a> '
|
352 |
-
list_html += f'<a href="/files/delete/{encoded}" style="color:red">[Delete]</a>{preview}</li>'
|
353 |
-
|
354 |
-
return f'''
|
355 |
-
<h2>Browsing: /{path}</h2>
|
356 |
-
<ul>{list_html}</ul>
|
357 |
-
<h3>Upload File</h3>
|
358 |
-
<form method=post enctype=multipart/form-data action="/files/upload/{path}">
|
359 |
-
<input type=file name=file>
|
360 |
-
<input type=submit value=Upload>
|
361 |
-
</form>
|
362 |
-
'''
|
363 |
-
|
364 |
-
@router.post("/files/upload/{path:path}")
|
365 |
-
async def upload_file(path: str, file: UploadFile):
|
366 |
-
full_path = get_safe_path(path)
|
367 |
-
if not os.path.exists(full_path):
|
368 |
-
os.makedirs(full_path)
|
369 |
-
file_path = os.path.join(full_path, file.filename)
|
370 |
-
with open(file_path, "wb") as f:
|
371 |
-
f.write(await file.read())
|
372 |
-
return RedirectResponse(url=f"/files/{path}", status_code=303)
|
373 |
-
|
374 |
-
@router.get("/files/delete/{path:path}")
|
375 |
-
async def delete_file(path: str):
|
376 |
-
try:
|
377 |
-
file_path = get_safe_path(path)
|
378 |
-
if os.path.isfile(file_path):
|
379 |
-
os.remove(file_path)
|
380 |
-
return RedirectResponse(url="/files/" + os.path.dirname(path), status_code=303)
|
381 |
-
return HTMLResponse("Not a file", status_code=400)
|
382 |
-
except Exception as e:
|
383 |
-
return HTMLResponse(f"Error: {str(e)}", status_code=400)
|
384 |
-
|
385 |
-
|
386 |
prompt_server.add_routes()
|
387 |
-
prompt_server.app.include_router(router)
|
388 |
hijack_progress(prompt_server)
|
389 |
|
390 |
threading.Thread(target=prompt_worker, daemon=True, args=(q, prompt_server,)).start()
|
@@ -413,7 +331,6 @@ def start_comfyui(asyncio_loop=None):
|
|
413 |
|
414 |
|
415 |
if __name__ == "__main__":
|
416 |
-
|
417 |
# Running directly, just start ComfyUI.
|
418 |
logging.info("ComfyUI version: {}".format(comfyui_version.__version__))
|
419 |
|
|
|
10 |
import itertools
|
11 |
import utils.extra_config
|
12 |
import logging
|
|
|
13 |
|
14 |
if __name__ == "__main__":
|
15 |
#NOTE: These do not do anything on core ComfyUI which should already have no communication with the internet, they are for custom nodes.
|
|
|
55 |
|
56 |
setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)
|
57 |
|
|
|
|
|
58 |
def apply_custom_paths():
|
59 |
# extra model paths
|
60 |
extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
|
|
|
302 |
|
303 |
cuda_malloc_warning()
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
prompt_server.add_routes()
|
|
|
306 |
hijack_progress(prompt_server)
|
307 |
|
308 |
threading.Thread(target=prompt_worker, daemon=True, args=(q, prompt_server,)).start()
|
|
|
331 |
|
332 |
|
333 |
if __name__ == "__main__":
|
|
|
334 |
# Running directly, just start ComfyUI.
|
335 |
logging.info("ComfyUI version: {}".format(comfyui_version.__version__))
|
336 |
|