fred-dev commited on
Commit
359284a
·
verified ·
1 Parent(s): c373d7d

try file browser

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -10,6 +10,8 @@ from app.logger import setup_logger
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,6 +57,37 @@ if __name__ == "__main__":
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")
@@ -331,6 +364,9 @@ def start_comfyui(asyncio_loop=None):
331
 
332
 
333
  if __name__ == "__main__":
 
 
 
334
  # Running directly, just start ComfyUI.
335
  logging.info("ComfyUI version: {}".format(comfyui_version.__version__))
336
 
 
10
  import itertools
11
  import utils.extra_config
12
  import logging
13
+ from flask import Flask, request, send_from_directory, render_template_string
14
+ import threading
15
 
16
  if __name__ == "__main__":
17
  #NOTE: These do not do anything on core ComfyUI which should already have no communication with the internet, they are for custom nodes.
 
57
 
58
  setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)
59
 
60
+ def start_file_browser():
61
+ app = Flask(__name__)
62
+ UPLOAD_FOLDER = "/data"
63
+
64
+ @app.route("/files")
65
+ def index():
66
+ files = os.listdir(UPLOAD_FOLDER)
67
+ file_list = ''.join(f'<li><a href="/files/download/{f}">{f}</a></li>' for f in files)
68
+ return render_template_string('''
69
+ <h2>File Browser (/data)</h2>
70
+ <ul>{{ file_list | safe }}</ul>
71
+ <h3>Upload File</h3>
72
+ <form method=post enctype=multipart/form-data action="/files/upload">
73
+ <input type=file name=file>
74
+ <input type=submit value=Upload>
75
+ </form>
76
+ ''', file_list=file_list)
77
+
78
+ @app.route("/files/download/<path:filename>")
79
+ def download_file(filename):
80
+ return send_from_directory(UPLOAD_FOLDER, filename, as_attachment=True)
81
+
82
+ @app.route("/files/upload", methods=["POST"])
83
+ def upload_file():
84
+ f = request.files["file"]
85
+ f.save(os.path.join(UPLOAD_FOLDER, f.filename))
86
+ return 'Uploaded! <a href="/files">Go back</a>'
87
+
88
+ app.run(host="0.0.0.0", port=7861, debug=False)
89
+
90
+
91
  def apply_custom_paths():
92
  # extra model paths
93
  extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
 
364
 
365
 
366
  if __name__ == "__main__":
367
+ #start file browser
368
+ threading.Thread(target=start_file_browser, daemon=True).start()
369
+
370
  # Running directly, just start ComfyUI.
371
  logging.info("ComfyUI version: {}".format(comfyui_version.__version__))
372