AdityaAdaki commited on
Commit
25e8e76
·
1 Parent(s): 9870f48
Files changed (3) hide show
  1. .dockerignore +22 -0
  2. Dockerfile +7 -0
  3. app.py +9 -5
.dockerignore ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ .Python
6
+ env
7
+ pip-log.txt
8
+ pip-delete-this-directory.txt
9
+ .tox
10
+ .coverage
11
+ .coverage.*
12
+ .cache
13
+ nosetests.xml
14
+ coverage.xml
15
+ *.cover
16
+ *.log
17
+ .pytest_cache
18
+ .env
19
+ .venv
20
+ venv
21
+ .DS_Store
22
+ static/uploads/*
Dockerfile CHANGED
@@ -8,6 +8,10 @@ RUN apt-get update && \
8
  build-essential \
9
  && rm -rf /var/lib/apt/lists/*
10
 
 
 
 
 
11
  # Copy requirements first to leverage Docker cache
12
  COPY requirements.txt .
13
  RUN pip install --no-cache-dir -r requirements.txt
@@ -15,6 +19,9 @@ RUN pip install --no-cache-dir -r requirements.txt
15
  # Copy the rest of the application
16
  COPY . .
17
 
 
 
 
18
  # Make port 7860 available to the world outside this container
19
  EXPOSE 7860
20
 
 
8
  build-essential \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
+ # Create uploads directory and set permissions
12
+ RUN mkdir -p /code/static/uploads && \
13
+ chmod 777 /code/static/uploads
14
+
15
  # Copy requirements first to leverage Docker cache
16
  COPY requirements.txt .
17
  RUN pip install --no-cache-dir -r requirements.txt
 
19
  # Copy the rest of the application
20
  COPY . .
21
 
22
+ # Ensure uploads directory has correct permissions
23
+ RUN chmod 777 /code/static/uploads
24
+
25
  # Make port 7860 available to the world outside this container
26
  EXPOSE 7860
27
 
app.py CHANGED
@@ -18,10 +18,13 @@ import base64
18
  from concurrent.futures import ThreadPoolExecutor
19
  import asyncio
20
 
 
 
 
 
 
21
  app = Flask(__name__, static_folder='static')
22
- # Create a temporary directory for uploads
23
- TEMP_UPLOAD_DIR = tempfile.mkdtemp()
24
- app.config['UPLOAD_FOLDER'] = TEMP_UPLOAD_DIR
25
  app.config['MAX_CONTENT_LENGTH'] = 200 * 1024 * 1024 # 200MB max file size
26
  app.config['MAX_FILES'] = 10 # Maximum number of files that can be uploaded at once
27
 
@@ -111,7 +114,7 @@ def cleanup_old_files():
111
  os.remove(filepath)
112
  files_to_delete.append(filename)
113
  except Exception as e:
114
- app.logger.error(f"Error deleting file {filename}: {str(e)}")
115
 
116
  # Remove deleted files from timestamps
117
  for filename in files_to_delete:
@@ -163,6 +166,7 @@ def upload_file():
163
  file_timestamps[filename] = datetime.now()
164
  metadata = extract_metadata(filepath)
165
 
 
166
  return {
167
  'filename': file.filename,
168
  'success': True,
@@ -198,7 +202,7 @@ def serve_audio(filename):
198
 
199
  # Cleanup function to remove temp directory on shutdown
200
  def cleanup():
201
- shutil.rmtree(TEMP_UPLOAD_DIR, ignore_errors=True)
202
 
203
  atexit.register(cleanup)
204
 
 
18
  from concurrent.futures import ThreadPoolExecutor
19
  import asyncio
20
 
21
+ # Create uploads directory in the static folder instead of using tempfile
22
+ UPLOAD_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static', 'uploads')
23
+ if not os.path.exists(UPLOAD_DIR):
24
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
25
+
26
  app = Flask(__name__, static_folder='static')
27
+ app.config['UPLOAD_FOLDER'] = UPLOAD_DIR
 
 
28
  app.config['MAX_CONTENT_LENGTH'] = 200 * 1024 * 1024 # 200MB max file size
29
  app.config['MAX_FILES'] = 10 # Maximum number of files that can be uploaded at once
30
 
 
114
  os.remove(filepath)
115
  files_to_delete.append(filename)
116
  except Exception as e:
117
+ logger.error(f"Error deleting file {filename}: {str(e)}")
118
 
119
  # Remove deleted files from timestamps
120
  for filename in files_to_delete:
 
166
  file_timestamps[filename] = datetime.now()
167
  metadata = extract_metadata(filepath)
168
 
169
+ # Update the filepath to use relative URL
170
  return {
171
  'filename': file.filename,
172
  'success': True,
 
202
 
203
  # Cleanup function to remove temp directory on shutdown
204
  def cleanup():
205
+ shutil.rmtree(UPLOAD_DIR, ignore_errors=True)
206
 
207
  atexit.register(cleanup)
208