Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile +42 -0
- download.py +42 -0
Dockerfile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use the specified RunPod base image with CUDA support and Python 3.8
|
| 2 |
+
FROM python:3.8-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
+
build-essential \
|
| 7 |
+
python3-dev \
|
| 8 |
+
ffmpeg \
|
| 9 |
+
aria2 \
|
| 10 |
+
git \
|
| 11 |
+
git-lfs \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# Clone the repository into the container
|
| 15 |
+
ARG CACHEBUST=1
|
| 16 |
+
RUN git clone https://huggingface.co/spaces/smjain/Advanced-RVC-Inference /app
|
| 17 |
+
|
| 18 |
+
# Set the working directory to the cloned repository to run commands inside it
|
| 19 |
+
WORKDIR /app
|
| 20 |
+
|
| 21 |
+
# Install Git Large File Storage (LFS), then pull LFS files
|
| 22 |
+
RUN git lfs install && git lfs pull
|
| 23 |
+
|
| 24 |
+
# Create a virtual environment named 'infer' and activate it
|
| 25 |
+
#RUN python3 -m venv /venv/infer
|
| 26 |
+
#ENV PATH="/venv/infer/bin:$PATH"
|
| 27 |
+
|
| 28 |
+
# Upgrade pip and install Python dependencies from the project's requirements.txt
|
| 29 |
+
# Also, install Flask and av as specified
|
| 30 |
+
RUN pip install --upgrade pip && \
|
| 31 |
+
pip install --upgrade -r requirements.txt --no-cache-dir && \
|
| 32 |
+
pip install flask av boto3 flask_dance
|
| 33 |
+
|
| 34 |
+
# Move PyTorch model weights into the weights directory if necessary
|
| 35 |
+
RUN mv *.pth weights/ || echo "No weights to move"
|
| 36 |
+
|
| 37 |
+
# Setting Flask application
|
| 38 |
+
# Expose the port Flask is running on
|
| 39 |
+
EXPOSE 5000
|
| 40 |
+
|
| 41 |
+
# Command to directly run the Flask application script
|
| 42 |
+
CMD ["python", "myinfer_latest.py"]
|
download.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, send_file, request, jsonify
|
| 2 |
+
import boto3
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
# AWS / DigitalOcean Spaces credentials
|
| 8 |
+
ACCESS_ID = os.getenv('ACCESS_ID', 'DO0026WEQUG4WF6WQNJ9')
|
| 9 |
+
SECRET_KEY = os.getenv('SECRET_KEY', 'UG7kQicGgWmkfVmESWK889RxZG49UqV7vRfYUJDFFUo')
|
| 10 |
+
|
| 11 |
+
@app.route('/download/<filename>', methods=['GET'])
|
| 12 |
+
def download_file(filename):
|
| 13 |
+
# Configure the client with your credentials
|
| 14 |
+
session = boto3.session.Session()
|
| 15 |
+
client = session.client('s3',
|
| 16 |
+
region_name='nyc3',
|
| 17 |
+
endpoint_url='https://nyc3.digitaloceanspaces.com',
|
| 18 |
+
aws_access_key_id=ACCESS_ID,
|
| 19 |
+
aws_secret_access_key=SECRET_KEY)
|
| 20 |
+
|
| 21 |
+
# Define the bucket and object key
|
| 22 |
+
bucket_name = 'sing' # Your bucket name
|
| 23 |
+
object_key = f'{filename}' # Construct the object key
|
| 24 |
+
|
| 25 |
+
# Define the local path to save the file
|
| 26 |
+
local_file_path = os.path.join('weights', filename)
|
| 27 |
+
|
| 28 |
+
# Download the file from the bucket
|
| 29 |
+
try:
|
| 30 |
+
client.download_file(bucket_name, object_key, local_file_path)
|
| 31 |
+
except client.exceptions.NoSuchKey:
|
| 32 |
+
return jsonify({'error': 'File not found in the bucket'}), 404
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return jsonify({'error': str(e)}), 500
|
| 35 |
+
|
| 36 |
+
# Optional: Send the file directly to the client
|
| 37 |
+
# return send_file(local_file_path, as_attachment=True)
|
| 38 |
+
|
| 39 |
+
return jsonify({'success': True, 'message': 'File downloaded successfully', 'file_path': local_file_path})
|
| 40 |
+
|
| 41 |
+
if __name__ == '__main__':
|
| 42 |
+
app.run(debug=True)
|