Hatman commited on
Commit
1000c7c
·
verified ·
1 Parent(s): b245167

Limit Storage of Pics

Browse files
Files changed (1) hide show
  1. main.py +16 -12
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 os.listdir(pictures_directory):
73
- if filename.endswith('.json'):
74
- file_path = os.path.join(pictures_directory, filename)
75
- with open(file_path, 'r') as file:
76
- data = json.load(file)
77
-
78
- # For JSON formatting, ensure only the first item doesn't have a preceding comma
79
- if first:
80
- first = False
81
- else:
82
- yield ','
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