summaryrefslogtreecommitdiffstats
path: root/g4f/gui/server
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g4f/gui/server/backend.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py
index dc1b1080..e24d4da2 100644
--- a/g4f/gui/server/backend.py
+++ b/g4f/gui/server/backend.py
@@ -1,5 +1,6 @@
import json
-from flask import request, Flask
+import os
+from flask import request, Flask, jsonify, send_from_directory
from g4f.image import is_allowed_extension, to_image
from .api import Api
@@ -54,6 +55,10 @@ class Backend_Api(Api):
'/images/<path:name>': {
'function': self.serve_images,
'methods': ['GET']
+ },
+ '/images': {
+ 'function': self.get_images,
+ 'methods': ['GET']
}
}
@@ -110,4 +115,19 @@ class Backend_Api(Api):
Returns:
str: A JSON formatted string.
"""
- return json.dumps(super()._format_json(response_type, content)) + "\n" \ No newline at end of file
+ return json.dumps(super()._format_json(response_type, content)) + "\n"
+
+ @staticmethod
+ def get_images():
+ images_dir = "./generated_images"
+ try:
+ images = [f for f in os.listdir(images_dir) if os.path.isfile(os.path.join(images_dir, f))]
+ images = [f"/images/{image}" for image in images if image.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp'))]
+ return jsonify(images)
+ except Exception as e:
+ return str(e), 500
+
+ @staticmethod
+ def serve_images(name):
+ images_dir = "./generated_images"
+ return send_from_directory(os.path.abspath(images_dir), name)