Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -86,20 +86,20 @@ def save_results(text, label):
|
|
86 |
# Save to JSON
|
87 |
if not os.path.exists(RESULTS_JSON):
|
88 |
with open(RESULTS_JSON, "w") as f:
|
89 |
-
json.dump([], f)
|
90 |
with open(RESULTS_JSON, "r+") as f:
|
91 |
-
content = json.load(f)
|
92 |
-
content.append(data)
|
93 |
-
f.seek(0)
|
94 |
-
json.dump(content, f, indent=4)
|
95 |
|
96 |
# Save to CSV
|
97 |
file_exists = os.path.exists(RESULTS_CSV)
|
98 |
with open(RESULTS_CSV, "a", newline="") as f:
|
99 |
writer = csv.DictWriter(f, fieldnames=["text", "label"])
|
100 |
if not file_exists:
|
101 |
-
writer.writeheader()
|
102 |
-
writer.writerow(data)
|
103 |
|
104 |
# Gradio Interface
|
105 |
image_input = gr.Image()
|
|
|
86 |
# Save to JSON
|
87 |
if not os.path.exists(RESULTS_JSON):
|
88 |
with open(RESULTS_JSON, "w") as f:
|
89 |
+
json.dump([], f) # Initialize an empty list if file doesn't exist
|
90 |
with open(RESULTS_JSON, "r+") as f:
|
91 |
+
content = json.load(f) # Load current content
|
92 |
+
content.append(data) # Append new data
|
93 |
+
f.seek(0) # Go back to the start of the file
|
94 |
+
json.dump(content, f, indent=4) # Save updated content
|
95 |
|
96 |
# Save to CSV
|
97 |
file_exists = os.path.exists(RESULTS_CSV)
|
98 |
with open(RESULTS_CSV, "a", newline="") as f:
|
99 |
writer = csv.DictWriter(f, fieldnames=["text", "label"])
|
100 |
if not file_exists:
|
101 |
+
writer.writeheader() # Write header if file is new
|
102 |
+
writer.writerow(data) # Append new data
|
103 |
|
104 |
# Gradio Interface
|
105 |
image_input = gr.Image()
|