Spaces:
Configuration error
Configuration error
Commit
·
bc8daa2
1
Parent(s):
8ccb7de
quick
Browse files- app.py +23 -8
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,10 +1,20 @@
|
|
| 1 |
# app.py
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
# Removed imports: pandas, openpyxl, datetime, timedelta, os, tempfile
|
| 4 |
|
| 5 |
# Import the processing function from main.py
|
| 6 |
from main import process_files
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def generate_report(file1_obj, file2_obj):
|
| 9 |
"""
|
| 10 |
Gradio wrapper function to handle file uploads and call the main processing logic.
|
|
@@ -18,35 +28,40 @@ def generate_report(file1_obj, file2_obj):
|
|
| 18 |
Raises:
|
| 19 |
gr.Error: If file processing fails.
|
| 20 |
"""
|
|
|
|
| 21 |
if file1_obj is None or file2_obj is None:
|
|
|
|
| 22 |
raise gr.Error("Please upload both required files.")
|
| 23 |
|
| 24 |
try:
|
| 25 |
# Gradio provides temporary paths for uploaded files
|
| 26 |
file1_path = file1_obj.name
|
| 27 |
file2_path = file2_obj.name
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
# Define the output filename
|
| 30 |
output_filename = "generated_report.xlsx"
|
|
|
|
| 31 |
|
| 32 |
# Call the core processing logic from main.py
|
| 33 |
-
|
| 34 |
result_path = process_files(file1_path, file2_path, output_filename)
|
| 35 |
-
|
| 36 |
|
| 37 |
if result_path:
|
|
|
|
| 38 |
# Return the path of the generated file for Gradio to serve
|
| 39 |
return result_path
|
| 40 |
else:
|
| 41 |
# If process_files returned None, it means an error occurred
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
# Catch any other unexpected errors during the wrapper execution
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
print(traceback.format_exc())
|
| 49 |
-
raise gr.Error(f"An unexpected error occurred: {e}")
|
| 50 |
|
| 51 |
|
| 52 |
# Create Gradio Interface
|
|
|
|
| 1 |
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
+
import logging # Import logging
|
| 4 |
+
import sys # Import sys to output to stderr
|
| 5 |
# Removed imports: pandas, openpyxl, datetime, timedelta, os, tempfile
|
| 6 |
|
| 7 |
# Import the processing function from main.py
|
| 8 |
from main import process_files
|
| 9 |
|
| 10 |
+
# --- Configure Logging --- (Configure before functions)
|
| 11 |
+
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 12 |
+
logging.basicConfig(level=logging.INFO, # Use INFO for general info, DEBUG for more detail
|
| 13 |
+
format=log_format,
|
| 14 |
+
handlers=[logging.StreamHandler(sys.stderr)]) # Output to stderr
|
| 15 |
+
|
| 16 |
+
logger = logging.getLogger(__name__) # Get logger for this module
|
| 17 |
+
|
| 18 |
def generate_report(file1_obj, file2_obj):
|
| 19 |
"""
|
| 20 |
Gradio wrapper function to handle file uploads and call the main processing logic.
|
|
|
|
| 28 |
Raises:
|
| 29 |
gr.Error: If file processing fails.
|
| 30 |
"""
|
| 31 |
+
logger.info("generate_report function called.")
|
| 32 |
if file1_obj is None or file2_obj is None:
|
| 33 |
+
logger.error("Missing one or both input files.")
|
| 34 |
raise gr.Error("Please upload both required files.")
|
| 35 |
|
| 36 |
try:
|
| 37 |
# Gradio provides temporary paths for uploaded files
|
| 38 |
file1_path = file1_obj.name
|
| 39 |
file2_path = file2_obj.name
|
| 40 |
+
logger.info(f"Input file 1 path: {file1_path}")
|
| 41 |
+
logger.info(f"Input file 2 path: {file2_path}")
|
| 42 |
|
| 43 |
+
# Define the output filename
|
| 44 |
output_filename = "generated_report.xlsx"
|
| 45 |
+
logger.info(f"Target output base filename: {output_filename}")
|
| 46 |
|
| 47 |
# Call the core processing logic from main.py
|
| 48 |
+
logger.info(f"Calling process_files...")
|
| 49 |
result_path = process_files(file1_path, file2_path, output_filename)
|
| 50 |
+
logger.info(f"process_files returned: {result_path}")
|
| 51 |
|
| 52 |
if result_path:
|
| 53 |
+
logger.info(f"Report generation successful. Returning path: {result_path}")
|
| 54 |
# Return the path of the generated file for Gradio to serve
|
| 55 |
return result_path
|
| 56 |
else:
|
| 57 |
# If process_files returned None, it means an error occurred
|
| 58 |
+
logger.error("process_files returned None, indicating failure.")
|
| 59 |
+
raise gr.Error("Failed to generate the report. Check application logs for details.")
|
| 60 |
|
| 61 |
except Exception as e:
|
| 62 |
# Catch any other unexpected errors during the wrapper execution
|
| 63 |
+
logger.exception("An unexpected error occurred in the Gradio wrapper (generate_report)") # Logs exception info automatically
|
| 64 |
+
raise gr.Error(f"An unexpected error occurred. Check application logs for details.") # User-friendly message
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
# Create Gradio Interface
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
pandas>=1.3.0
|
| 2 |
openpyxl>=3.0.0
|
|
|
|
| 3 |
gradio>=3.0
|
|
|
|
| 1 |
pandas>=1.3.0
|
| 2 |
openpyxl>=3.0.0
|
| 3 |
+
xlrd>=1.2.0
|
| 4 |
gradio>=3.0
|