Kiran5 commited on
Commit
68ecef9
·
1 Parent(s): 2a46da5

adding files

Browse files
Files changed (1) hide show
  1. main.py +15 -10
main.py CHANGED
@@ -156,25 +156,29 @@ def internal_server_error_handler(exc):
156
  log_dir = '/home/user/logs' # Update to a directory inside user's home directory
157
  if not os.path.exists(log_dir):
158
  os.makedirs(log_dir, exist_ok=True)
 
 
 
159
 
160
  # Configure basic logging
161
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
162
 
163
  # Debugging: log environment variables
164
- logging.info(f"PORT: {os.getenv('PORT')}")
165
- logging.info(f"THREADS: {os.getenv('THREADS')}")
166
- logging.info(f"CONNECTION_LIMIT: {os.getenv('CONNECTION_LIMIT')}")
167
- logging.info(f"CHANNEL_TIMEOUT: {os.getenv('CHANNEL_TIMEOUT')}")
168
 
169
- # Use Waitress for production server, or Flask for development
170
  if __name__ == "__main__":
171
  try:
172
- # Start the Flask application
173
- logging.info("Starting the application...")
174
- serve(app1, host="0.0.0.0", port=int(os.getenv("PORT", 7860)), threads=int(os.getenv('THREADS', 6)),
175
- connection_limit=int(os.getenv('CONNECTION_LIMIT', 500)), channel_timeout=int(os.getenv('CHANNEL_TIMEOUT', 120)))
 
176
  except Exception as e:
177
- logging.error(f"Error starting the application: {e}")
178
  raise
179
 
180
 
@@ -184,3 +188,4 @@ if __name__ == "__main__":
184
 
185
 
186
 
 
 
156
  log_dir = '/home/user/logs' # Update to a directory inside user's home directory
157
  if not os.path.exists(log_dir):
158
  os.makedirs(log_dir, exist_ok=True)
159
+ logging.info(f"Created log directory at: {log_dir}")
160
+ else:
161
+ logging.info(f"Log directory already exists: {log_dir}")
162
 
163
  # Configure basic logging
164
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
165
 
166
  # Debugging: log environment variables
167
+ logging.info(f"PORT: {os.getenv('PORT', 'Not Set')}")
168
+ logging.info(f"THREADS: {os.getenv('THREADS', 'Not Set')}")
169
+ logging.info(f"CONNECTION_LIMIT: {os.getenv('CONNECTION_LIMIT', 'Not Set')}")
170
+ logging.info(f"CHANNEL_TIMEOUT: {os.getenv('CHANNEL_TIMEOUT', 'Not Set')}")
171
 
172
+ # Use Flask development server for Hugging Face Spaces compatibility (instead of Waitress)
173
  if __name__ == "__main__":
174
  try:
175
+ # Log the server startup info
176
+ logging.info("Starting Flask application...")
177
+
178
+ # Start the Flask application with the development server for testing
179
+ app1.run(host="0.0.0.0", port=int(os.getenv("PORT", 7860)), threaded=True)
180
  except Exception as e:
181
+ logging.error(f"Error starting Flask application: {e}")
182
  raise
183
 
184
 
 
188
 
189
 
190
 
191
+