Spaces:
Running
Running
Limit Storage of Pics
Browse files
main.py
CHANGED
@@ -65,22 +65,26 @@ class Core(BaseModel):
|
|
65 |
async def core():
|
66 |
if not os.path.exists(pictures_directory):
|
67 |
os.makedirs(pictures_directory)
|
|
|
|
|
|
|
|
|
|
|
68 |
async def generator():
|
69 |
# Start JSON array
|
70 |
yield '['
|
71 |
first = True
|
72 |
-
for filename in
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
yield json.dumps({"base64": data["base64image"], "prompt": data["returnedPrompt"]})
|
84 |
# End JSON array
|
85 |
yield ']'
|
86 |
|
|
|
65 |
async def core():
|
66 |
if not os.path.exists(pictures_directory):
|
67 |
os.makedirs(pictures_directory)
|
68 |
+
files = sorted([f for f in os.listdir(pictures_directory) if f.endswith('.json')])
|
69 |
+
first_100_files = files[:100]
|
70 |
+
for file in files[100:]:
|
71 |
+
os.remove(os.path.join(pictures_directory, file))
|
72 |
+
|
73 |
async def generator():
|
74 |
# Start JSON array
|
75 |
yield '['
|
76 |
first = True
|
77 |
+
for filename in first_100_files:
|
78 |
+
file_path = os.path.join(pictures_directory, filename)
|
79 |
+
with open(file_path, 'r') as file:
|
80 |
+
data = json.load(file)
|
81 |
+
|
82 |
+
# For JSON formatting, ensure only the first item doesn't have a preceding comma
|
83 |
+
if first:
|
84 |
+
first = False
|
85 |
+
else:
|
86 |
+
yield ','
|
87 |
+
yield json.dumps({"base64": data["base64image"], "prompt": data["returnedPrompt"]})
|
|
|
88 |
# End JSON array
|
89 |
yield ']'
|
90 |
|