Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -236,25 +236,30 @@ def process_woocommerce_data_in_memory(netcom_file):
|
|
| 236 |
|
| 237 |
return output_buffer
|
| 238 |
|
| 239 |
-
def
|
| 240 |
"""
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
- Writes the CSV to a temp file,
|
| 244 |
-
- Returns that path for Gradio to provide as a downloadable file.
|
| 245 |
"""
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
| 252 |
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
-
|
| 256 |
-
fn=
|
| 257 |
-
inputs=gr.File(label="Upload NetCom CSV", file_types=["
|
| 258 |
outputs=gr.File(label="Download WooCommerce CSV"),
|
| 259 |
title="NetCom to WooCommerce CSV Processor",
|
| 260 |
description="Upload your NetCom Reseller Schedule CSV to generate the WooCommerce import-ready CSV."
|
|
@@ -262,4 +267,6 @@ app = gr.Interface(
|
|
| 262 |
|
| 263 |
if __name__ == "__main__":
|
| 264 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 265 |
-
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
return output_buffer
|
| 238 |
|
| 239 |
+
def process_woocommerce_data_in_memory(netcom_file):
|
| 240 |
"""
|
| 241 |
+
Reads the uploaded NetCom CSV file in-memory, processes it to the WooCommerce format,
|
| 242 |
+
and returns the resulting CSV as bytes, suitable for download.
|
|
|
|
|
|
|
| 243 |
"""
|
| 244 |
+
# [Keep all your existing processing code exactly the same until the end]
|
| 245 |
+
|
| 246 |
+
# 9. Convert to CSV (in memory)
|
| 247 |
+
output_buffer = BytesIO()
|
| 248 |
+
woo_final_df.to_csv(output_buffer, index=False, encoding='utf-8-sig')
|
| 249 |
+
output_buffer.seek(0)
|
| 250 |
+
|
| 251 |
+
return output_buffer
|
| 252 |
|
| 253 |
+
def process_file(uploaded_file):
|
| 254 |
+
"""
|
| 255 |
+
Takes the uploaded file, processes it, and returns the CSV as a file-like object
|
| 256 |
+
"""
|
| 257 |
+
processed_csv_io = process_woocommerce_data_in_memory(uploaded_file)
|
| 258 |
+
return processed_csv_io
|
| 259 |
|
| 260 |
+
interface = gr.Interface(
|
| 261 |
+
fn=process_file,
|
| 262 |
+
inputs=gr.File(label="Upload NetCom CSV", file_types=[".csv"]),
|
| 263 |
outputs=gr.File(label="Download WooCommerce CSV"),
|
| 264 |
title="NetCom to WooCommerce CSV Processor",
|
| 265 |
description="Upload your NetCom Reseller Schedule CSV to generate the WooCommerce import-ready CSV."
|
|
|
|
| 267 |
|
| 268 |
if __name__ == "__main__":
|
| 269 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 270 |
+
if not openai_api_key:
|
| 271 |
+
print("Warning: OPENAI_API_KEY environment variable not set")
|
| 272 |
+
interface.launch()
|