Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ import datetime
|
|
| 7 |
import difflib
|
| 8 |
import csv
|
| 9 |
import gradio as gr
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# Config / data loading
|
|
@@ -132,19 +134,23 @@ def upload_json(filepath):
|
|
| 132 |
return f"Error loading file: {e}", gr.update(choices=[])
|
| 133 |
|
| 134 |
def download_current_csv(history):
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
| 137 |
writer = csv.writer(f)
|
| 138 |
writer.writerow(["role","content"])
|
| 139 |
for msg in history:
|
| 140 |
writer.writerow([msg["role"], msg["content"]])
|
| 141 |
-
return
|
| 142 |
|
| 143 |
def download_current_json():
|
| 144 |
-
|
| 145 |
-
|
|
|
|
| 146 |
json.dump(QUOTES, f, indent=2, ensure_ascii=False)
|
| 147 |
-
return
|
| 148 |
|
| 149 |
# -----------------------------
|
| 150 |
# UI
|
|
|
|
| 7 |
import difflib
|
| 8 |
import csv
|
| 9 |
import gradio as gr
|
| 10 |
+
import tempfile
|
| 11 |
+
import shutil
|
| 12 |
|
| 13 |
# -----------------------------
|
| 14 |
# Config / data loading
|
|
|
|
| 134 |
return f"Error loading file: {e}", gr.update(choices=[])
|
| 135 |
|
| 136 |
def download_current_csv(history):
|
| 137 |
+
if not history:
|
| 138 |
+
return None
|
| 139 |
+
tmpdir = tempfile.mkdtemp()
|
| 140 |
+
filepath = os.path.join(tmpdir, "conversation_export.csv")
|
| 141 |
+
with open(filepath, "w", newline="", encoding="utf-8") as f:
|
| 142 |
writer = csv.writer(f)
|
| 143 |
writer.writerow(["role","content"])
|
| 144 |
for msg in history:
|
| 145 |
writer.writerow([msg["role"], msg["content"]])
|
| 146 |
+
return filepath
|
| 147 |
|
| 148 |
def download_current_json():
|
| 149 |
+
tmpdir = tempfile.mkdtemp()
|
| 150 |
+
filepath = os.path.join(tmpdir, "quotes_export.json")
|
| 151 |
+
with open(filepath, "w", encoding="utf-8") as f:
|
| 152 |
json.dump(QUOTES, f, indent=2, ensure_ascii=False)
|
| 153 |
+
return filepath
|
| 154 |
|
| 155 |
# -----------------------------
|
| 156 |
# UI
|