Shriharsh commited on
Commit
c428223
·
verified ·
1 Parent(s): 76d85a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -8,7 +8,6 @@ import os
8
  # Set up logging with a dedicated file handler
9
  logger = logging.getLogger('SupportBot')
10
  logger.setLevel(logging.INFO)
11
- # Remove any existing handlers to avoid conflicts
12
  if logger.handlers:
13
  logger.handlers.clear()
14
 
@@ -81,12 +80,19 @@ def process_file(file, state):
81
  logger.info("No file uploaded")
82
  file_handler.flush()
83
  return [("Bot", "Please upload a file.")], state
84
-
85
  # Save the uploaded file to a temporary location
86
  file_path = file.name
87
  temp_file_path = os.path.join("/tmp", os.path.basename(file_path))
88
  with open(temp_file_path, "wb") as f:
89
- f.write(file.read())
 
 
 
 
 
 
 
90
 
91
  if temp_file_path.lower().endswith(".pdf"):
92
  logger.info(f"Processing PDF file: {temp_file_path}")
 
8
  # Set up logging with a dedicated file handler
9
  logger = logging.getLogger('SupportBot')
10
  logger.setLevel(logging.INFO)
 
11
  if logger.handlers:
12
  logger.handlers.clear()
13
 
 
80
  logger.info("No file uploaded")
81
  file_handler.flush()
82
  return [("Bot", "Please upload a file.")], state
83
+
84
  # Save the uploaded file to a temporary location
85
  file_path = file.name
86
  temp_file_path = os.path.join("/tmp", os.path.basename(file_path))
87
  with open(temp_file_path, "wb") as f:
88
+ # Check if the file has a 'read' method; if not, assume it's already the content.
89
+ if hasattr(file, "read"):
90
+ content = file.read()
91
+ else:
92
+ content = file
93
+ if isinstance(content, str):
94
+ content = content.encode("utf-8")
95
+ f.write(content)
96
 
97
  if temp_file_path.lower().endswith(".pdf"):
98
  logger.info(f"Processing PDF file: {temp_file_path}")