Commit
·
34c3ae0
1
Parent(s):
c1a0bc2
update download functionality to work in HF Spaces
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import re
|
| 2 |
import os
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -23,17 +24,14 @@ logs_df = PandasDataFrame(columns=logs_columns)
|
|
| 23 |
|
| 24 |
def download_logs():
|
| 25 |
global logs_df
|
| 26 |
-
# Check for the current operating system's desktop path
|
| 27 |
-
if os.name == 'nt': # For Windows
|
| 28 |
-
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
|
| 29 |
-
else: # For macOS and Linux
|
| 30 |
-
desktop = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
|
| 38 |
|
| 39 |
def build_context(row):
|
|
|
|
| 1 |
import re
|
| 2 |
import os
|
| 3 |
+
from io import BytesIO
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 24 |
|
| 25 |
def download_logs():
|
| 26 |
global logs_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Convert the DataFrame into a CSV byte stream
|
| 29 |
+
output = BytesIO()
|
| 30 |
+
logs_df.to_csv(output, index=False)
|
| 31 |
+
output.seek(0) # Rewind the buffer
|
| 32 |
|
| 33 |
+
# Return the CSV byte stream and filename for Gradio to generate a download link
|
| 34 |
+
return output, "classification_logs.csv"
|
| 35 |
|
| 36 |
|
| 37 |
def build_context(row):
|