Spaces:
Sleeping
Sleeping
ariankhalfani
commited on
Commit
•
7d7eb41
1
Parent(s):
e6eaf4a
Update app.py
Browse files
app.py
CHANGED
@@ -209,17 +209,23 @@ def download_file(choice):
|
|
209 |
if not os.path.exists(directory):
|
210 |
os.makedirs(directory)
|
211 |
|
|
|
|
|
212 |
if choice == "Database (.db)":
|
213 |
-
#
|
214 |
-
db_file_path
|
215 |
-
return db_file_path # Return the path as a string
|
216 |
|
217 |
elif choice == "Database (.html)":
|
218 |
# Connect to the SQLite database
|
219 |
-
conn = sqlite3.connect(
|
220 |
|
221 |
-
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
# Close the database connection
|
225 |
conn.close()
|
@@ -230,8 +236,9 @@ def download_file(choice):
|
|
230 |
# Save the DataFrame as an HTML file
|
231 |
df.to_html(html_file_path, index=False)
|
232 |
|
233 |
-
|
234 |
-
|
|
|
235 |
# Initialize the database
|
236 |
init_db()
|
237 |
|
|
|
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 |
+
# Return the database file path
|
216 |
+
return db_file_path
|
|
|
217 |
|
218 |
elif choice == "Database (.html)":
|
219 |
# Connect to the SQLite database
|
220 |
+
conn = sqlite3.connect(db_file_path)
|
221 |
|
222 |
+
try:
|
223 |
+
# Attempt to read the results table into a DataFrame
|
224 |
+
df = pd.read_sql_query("SELECT * FROM results", conn)
|
225 |
+
except pd.errors.DatabaseError as e:
|
226 |
+
# Handle the case where the table doesn't exist
|
227 |
+
conn.close()
|
228 |
+
raise ValueError("Table 'results' does not exist in the database.") from e
|
229 |
|
230 |
# Close the database connection
|
231 |
conn.close()
|
|
|
236 |
# Save the DataFrame as an HTML file
|
237 |
df.to_html(html_file_path, index=False)
|
238 |
|
239 |
+
# Return the path to the HTML file
|
240 |
+
return html_file_path
|
241 |
+
|
242 |
# Initialize the database
|
243 |
init_db()
|
244 |
|