syk101 commited on
Commit
a6a5774
·
verified ·
1 Parent(s): ddb6e21

Upload 233 files

Browse files
NewProject ali 9 dec 2/Dockerfile CHANGED
@@ -27,4 +27,4 @@ ENV PYTHONPATH=/app
27
  EXPOSE 7860
28
 
29
  # Run the application
30
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
 
27
  EXPOSE 7860
28
 
29
  # Run the application
30
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--chdir", "/app", "app:app"]
NewProject ali 9 dec 2/FIX_SUMMARY.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Runtime Error Fix Summary
2
+
3
+ ## Problem
4
+ The application was failing with a `ModuleNotFoundError: No module named 'controller'` when deployed. This error occurred because Python couldn't locate the `controller` package during the import process in `app.py`.
5
+
6
+ ## Root Cause
7
+ The issue was related to Python's module search path. When the application was deployed, the working directory or Python path didn't include the directory containing the `controller` package, causing the import to fail.
8
+
9
+ ## Fixes Applied
10
+
11
+ ### 1. Updated Dockerfile
12
+ Added `--chdir /app` to the gunicorn command to ensure the working directory is correctly set:
13
+ ```dockerfile
14
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--chdir", "/app", "app:app"]
15
+ ```
16
+
17
+ ### 2. Updated Procfile
18
+ Added `--chdir /app` to the gunicorn command for Heroku/Render deployments:
19
+ ```
20
+ web: gunicorn --bind 0.0.0.0:$PORT --chdir /app app:app
21
+ ```
22
+
23
+ ### 3. Updated render.yaml
24
+ Added `--chdir /app` to the startCommand for Render deployments:
25
+ ```yaml
26
+ startCommand: "gunicorn --bind 0.0.0.0:$PORT --chdir /app app:app"
27
+ ```
28
+
29
+ ### 4. Modified app.py
30
+ Added explicit Python path manipulation at the beginning of the file to ensure the current directory is in the Python path:
31
+ ```python
32
+ import sys
33
+ import os
34
+
35
+ # Add the current directory to Python path
36
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
37
+ ```
38
+
39
+ ## Why These Fixes Work
40
+ 1. The `--chdir` option ensures that gunicorn starts in the correct directory where all the application modules are located.
41
+ 2. The Python path modification in `app.py` provides a fallback mechanism to ensure the current directory is always in the Python path, regardless of how the application is started.
42
+
43
+ These changes should resolve the ModuleNotFoundError and allow the application to start successfully in various deployment environments.
NewProject ali 9 dec 2/Procfile CHANGED
@@ -1 +1 @@
1
- web: gunicorn --bind 0.0.0.0:$PORT app:app
 
1
+ web: gunicorn --bind 0.0.0.0:$PORT --chdir /app app:app
NewProject ali 9 dec 2/app.py CHANGED
@@ -1,4 +1,10 @@
1
  # app.py
 
 
 
 
 
 
2
  from flask import Flask, render_template
3
  from flask_login import login_required
4
  from controller.pix2text_controller import pix2text_bp
 
1
  # app.py
2
+ import sys
3
+ import os
4
+
5
+ # Add the current directory to Python path
6
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
7
+
8
  from flask import Flask, render_template
9
  from flask_login import login_required
10
  from controller.pix2text_controller import pix2text_bp
NewProject ali 9 dec 2/render.yaml CHANGED
@@ -3,7 +3,7 @@ services:
3
  name: texlab
4
  env: python
5
  buildCommand: "pip install -r requirements-render.txt"
6
- startCommand: "gunicorn --bind 0.0.0.0:$PORT app:app"
7
  envVars:
8
  - key: PYTHON_VERSION
9
  value: 3.11.6
 
3
  name: texlab
4
  env: python
5
  buildCommand: "pip install -r requirements-render.txt"
6
+ startCommand: "gunicorn --bind 0.0.0.0:$PORT --chdir /app app:app"
7
  envVars:
8
  - key: PYTHON_VERSION
9
  value: 3.11.6