Spaces:
Sleeping
Sleeping
ariankhalfani
commited on
Commit
•
71c8c81
1
Parent(s):
259a2bb
Update app.py
Browse files
app.py
CHANGED
@@ -203,20 +203,18 @@ def view_database():
|
|
203 |
|
204 |
# Function to download database or HTML file
|
205 |
def download_file(choice):
|
206 |
-
|
207 |
-
|
208 |
-
# Ensure the directory exists
|
209 |
-
if not os.path.exists(directory):
|
210 |
-
os.makedirs(directory)
|
211 |
-
|
212 |
-
db_file_path = os.path.join(directory, 'results.db')
|
213 |
|
214 |
if choice == "Database (.db)":
|
215 |
-
#
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
218 |
elif choice == "Database (.html)":
|
219 |
-
# Connect to the SQLite database
|
220 |
conn = sqlite3.connect(db_file_path)
|
221 |
|
222 |
try:
|
@@ -231,7 +229,7 @@ def download_file(choice):
|
|
231 |
conn.close()
|
232 |
|
233 |
# Define the path for the HTML file
|
234 |
-
html_file_path = os.path.join(
|
235 |
|
236 |
# Save the DataFrame as an HTML file
|
237 |
df.to_html(html_file_path, index=False)
|
|
|
203 |
|
204 |
# Function to download database or HTML file
|
205 |
def download_file(choice):
|
206 |
+
db_file_path = 'results.db' # Directly reference the existing database file
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
if choice == "Database (.db)":
|
209 |
+
# Check if the database file exists
|
210 |
+
if os.path.exists(db_file_path):
|
211 |
+
# Return the database file path directly
|
212 |
+
return db_file_path
|
213 |
+
else:
|
214 |
+
raise FileNotFoundError(f"{db_file_path} not found.")
|
215 |
+
|
216 |
elif choice == "Database (.html)":
|
217 |
+
# Connect to the existing SQLite database
|
218 |
conn = sqlite3.connect(db_file_path)
|
219 |
|
220 |
try:
|
|
|
229 |
conn.close()
|
230 |
|
231 |
# Define the path for the HTML file
|
232 |
+
html_file_path = os.path.join(tempfile.gettempdir(), "results.html")
|
233 |
|
234 |
# Save the DataFrame as an HTML file
|
235 |
df.to_html(html_file_path, index=False)
|