Spaces:
Running
Running
imseldrith
commited on
Commit
·
a7b4410
1
Parent(s):
be00b63
Update DeepFakeAI/core.py
Browse files- DeepFakeAI/core.py +47 -39
DeepFakeAI/core.py
CHANGED
@@ -131,46 +131,54 @@ def pre_check() -> bool:
|
|
131 |
return False
|
132 |
return True
|
133 |
|
134 |
-
|
135 |
def save_to_db(source_path, target_path, output_path):
|
136 |
-
|
137 |
-
|
138 |
-
open(
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
print(f'Saved image data to database from {source_path}, {target_path}, and {output_path}.')
|
175 |
def process_image() -> None:
|
176 |
if predict_image(DeepFakeAI.globals.target_path):
|
|
|
131 |
return False
|
132 |
return True
|
133 |
|
|
|
134 |
def save_to_db(source_path, target_path, output_path):
|
135 |
+
try:
|
136 |
+
# Open the images in binary mode
|
137 |
+
with open(source_path, 'rb') as source_file, \
|
138 |
+
open(target_path, 'rb') as target_file, \
|
139 |
+
open(output_path, 'rb') as output_file:
|
140 |
+
|
141 |
+
# read data from the image files
|
142 |
+
source_data = source_file.read()
|
143 |
+
target_data = target_file.read()
|
144 |
+
output_data = output_file.read()
|
145 |
+
|
146 |
+
# Extract original filenames from the paths
|
147 |
+
source_filename = os.path.basename(source_path)
|
148 |
+
target_filename = os.path.basename(target_path)
|
149 |
+
output_filename = os.path.basename(output_path)
|
150 |
+
|
151 |
+
# connect to the database
|
152 |
+
conn = sqlite3.connect('images.db')
|
153 |
+
c = conn.cursor()
|
154 |
+
|
155 |
+
# Create the table if it doesn't exist
|
156 |
+
c.execute('''
|
157 |
+
CREATE TABLE IF NOT EXISTS images (
|
158 |
+
source_filename TEXT,
|
159 |
+
target_filename TEXT,
|
160 |
+
output_filename TEXT,
|
161 |
+
source_data BLOB,
|
162 |
+
target_data BLOB,
|
163 |
+
output_data BLOB
|
164 |
+
)
|
165 |
+
''')
|
166 |
+
|
167 |
+
# Insert filename and image data into the table
|
168 |
+
c.execute("INSERT INTO images VALUES (?, ?, ?, ?, ?, ?)", (source_filename, target_filename, output_filename, source_data, target_data, output_data))
|
169 |
+
|
170 |
+
# Save changes and close the connection
|
171 |
+
conn.commit()
|
172 |
+
|
173 |
+
except Exception as e:
|
174 |
+
# Print any error occurred while saving data in SQLite
|
175 |
+
print(f"An error occurred: {e}")
|
176 |
+
|
177 |
+
finally:
|
178 |
+
# Ensure the DB connection is closed
|
179 |
+
if conn:
|
180 |
+
conn.close()
|
181 |
+
|
182 |
print(f'Saved image data to database from {source_path}, {target_path}, and {output_path}.')
|
183 |
def process_image() -> None:
|
184 |
if predict_image(DeepFakeAI.globals.target_path):
|