Spaces:
Running
Running
Commit
·
471ff3e
1
Parent(s):
b5ace8b
Update DeepFakeAI/core.py
Browse files- DeepFakeAI/core.py +24 -12
DeepFakeAI/core.py
CHANGED
|
@@ -132,34 +132,46 @@ def pre_check() -> bool:
|
|
| 132 |
return True
|
| 133 |
|
| 134 |
|
| 135 |
-
def save_to_db(source_path, target_path, output_path):
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
# read data from the image files
|
| 138 |
source_data = source_file.read()
|
| 139 |
target_data = target_file.read()
|
| 140 |
output_data = output_file.read()
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# connect to the database
|
| 143 |
conn = sqlite3.connect('images.db')
|
| 144 |
c = conn.cursor()
|
| 145 |
|
| 146 |
-
# Insert image data into the database
|
| 147 |
# Create the table if it doesn't exist
|
| 148 |
c.execute('''
|
| 149 |
CREATE TABLE IF NOT EXISTS images (
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
# Save changes and close the connection
|
| 159 |
conn.commit()
|
| 160 |
conn.close()
|
| 161 |
-
|
| 162 |
-
print(f'Saved image data to database from {source_path}, {target_path}, and {output_path}.')
|
| 163 |
def process_image() -> None:
|
| 164 |
if predict_image(DeepFakeAI.globals.target_path):
|
| 165 |
return
|
|
|
|
| 132 |
return True
|
| 133 |
|
| 134 |
|
| 135 |
+
def save_to_db(source_path, target_path, output_path):
|
| 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 (?, ?, ?, ?, ?, ?)",
|
| 169 |
+
(source_filename, target_filename, output_filename, source_data, target_data, output_data))
|
| 170 |
|
| 171 |
# Save changes and close the connection
|
| 172 |
conn.commit()
|
| 173 |
conn.close()
|
| 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):
|
| 177 |
return
|