Spaces:
Sleeping
Sleeping
VenkateshRoshan
commited on
Commit
·
157ba12
1
Parent(s):
d1ab5db
dockerfile and automatic deployment scripts added
Browse files- app.py +2 -2
- dockerfile +24 -0
- setup.sh +58 -23
app.py
CHANGED
@@ -13,7 +13,7 @@ import psutil
|
|
13 |
# device = 0 if torch.cuda.is_available() else -1
|
14 |
|
15 |
model_id = "openai/whisper-small"
|
16 |
-
client = InferenceClient(model_id)
|
17 |
pipe = pipeline("automatic-speech-recognition", model=model_id) #, device=device)
|
18 |
|
19 |
print(f'The Server is Running !!!')
|
@@ -107,4 +107,4 @@ with demo:
|
|
107 |
# # time_taken = gr.Textbox(label="Time taken", type="text") # Time taken outside the interfaces
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
-
demo.queue().launch()
|
|
|
13 |
# device = 0 if torch.cuda.is_available() else -1
|
14 |
|
15 |
model_id = "openai/whisper-small"
|
16 |
+
client = InferenceClient(model_id,token=os.getenv('HF_TOKEN'))
|
17 |
pipe = pipeline("automatic-speech-recognition", model=model_id) #, device=device)
|
18 |
|
19 |
print(f'The Server is Running !!!')
|
|
|
107 |
# # time_taken = gr.Textbox(label="Time taken", type="text") # Time taken outside the interfaces
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=5000)
|
dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10
|
2 |
+
|
3 |
+
ARG HF_TOKEN
|
4 |
+
|
5 |
+
ENV HF_TOKEN=${HF_TOKEN}
|
6 |
+
|
7 |
+
WORKDIR /app
|
8 |
+
|
9 |
+
# Install FFmpeg and other dependencies
|
10 |
+
RUN apt-get update
|
11 |
+
RUN apt-get install -y ffmpeg
|
12 |
+
RUN apt-get clean
|
13 |
+
|
14 |
+
# Copy the current directory contents into the container at /app
|
15 |
+
COPY . /app
|
16 |
+
|
17 |
+
# Install any needed packages specified in requirements.txt
|
18 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
19 |
+
|
20 |
+
# Make port 5000 available to the world outside this container
|
21 |
+
EXPOSE 5000
|
22 |
+
|
23 |
+
# Run app.py when the container launches
|
24 |
+
CMD ["python", "app.py"]
|
setup.sh
CHANGED
@@ -27,42 +27,77 @@ ssh-keygen -f my_key -t ed25519 -N ""
|
|
27 |
new_ssh_pub_key=$(<my_key.pub)
|
28 |
|
29 |
# Print the public key
|
30 |
-
echo "Public Key:"
|
31 |
-
echo "$new_ssh_pub_key"
|
32 |
|
33 |
# Use the old SSH key to connect to the server and append the new public key to authorized_keys
|
34 |
ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "echo '$new_ssh_pub_key' >> /home/student-admin/.ssh/authorized_keys && chmod 600 /home/student-admin/.ssh/authorized_keys"
|
35 |
|
36 |
-
# TODO : Comment the old ssh key in the authorized_keys file
|
37 |
-
#
|
38 |
-
|
39 |
-
# Verify if the key has been added successfully
|
40 |
echo "New public key added to authorized_keys on the server."
|
41 |
|
42 |
# Make a variable to store the SSH connection command with
|
43 |
SSH_CONNECTION="ssh -i my_key -p $PORT $USER@$HOST"
|
44 |
|
45 |
-
#
|
46 |
-
#
|
47 |
-
$SSH_CONNECTION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
|
|
|
|
|
|
50 |
|
51 |
-
#
|
52 |
-
|
53 |
-
$SSH_CONNECTION "python3 -m venv $VENV"
|
54 |
|
55 |
-
|
|
|
|
|
56 |
|
57 |
-
#
|
58 |
-
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
$SSH_CONNECTION "git clone $GIT_REPO_PATH"
|
63 |
|
64 |
-
#
|
65 |
-
|
66 |
-
$SSH_CONNECTION "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip install -r requirements.txt && python3 app.py"
|
67 |
|
68 |
-
|
|
|
27 |
new_ssh_pub_key=$(<my_key.pub)
|
28 |
|
29 |
# Print the public key
|
30 |
+
# echo "Public Key:"
|
31 |
+
# echo "$new_ssh_pub_key"
|
32 |
|
33 |
# Use the old SSH key to connect to the server and append the new public key to authorized_keys
|
34 |
ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "echo '$new_ssh_pub_key' >> /home/student-admin/.ssh/authorized_keys && chmod 600 /home/student-admin/.ssh/authorized_keys"
|
35 |
|
|
|
|
|
|
|
|
|
36 |
echo "New public key added to authorized_keys on the server."
|
37 |
|
38 |
# Make a variable to store the SSH connection command with
|
39 |
SSH_CONNECTION="ssh -i my_key -p $PORT $USER@$HOST"
|
40 |
|
41 |
+
# TODO : Comment the old ssh key in the authorized_keys file
|
42 |
+
# Use the new SSH key to connect to the server and install Docker
|
43 |
+
$SSH_CONNECTION << EOF
|
44 |
+
# Update existing package list
|
45 |
+
sudo apt-get update
|
46 |
+
|
47 |
+
# Install required packages for Docker
|
48 |
+
sudo apt-get install -y ca-certificates curl gnupg lsb-release
|
49 |
+
|
50 |
+
# Add Docker's official GPG key
|
51 |
+
sudo mkdir -p /etc/apt/keyrings
|
52 |
+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
53 |
+
|
54 |
+
# Set up the Docker repository
|
55 |
+
echo \
|
56 |
+
"deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
|
57 |
+
\$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
58 |
+
|
59 |
+
# Update the package list again
|
60 |
+
sudo apt-get update
|
61 |
+
|
62 |
+
# Install Docker Engine, Docker CLI, and containerd
|
63 |
+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
64 |
+
|
65 |
+
# Start and enable Docker service
|
66 |
+
sudo systemctl start docker
|
67 |
+
sudo systemctl enable docker
|
68 |
+
|
69 |
+
# Add current user to docker group (to run Docker commands without sudo)
|
70 |
+
sudo usermod -aG docker $USER
|
71 |
+
|
72 |
+
# Verify Docker installation
|
73 |
+
docker --version
|
74 |
+
EOF
|
75 |
+
|
76 |
+
echo "Docker has been installed on the server."
|
77 |
+
|
78 |
+
# Verify if the key has been added successfully
|
79 |
+
|
80 |
+
DOCKER_NAME=mlopscs2
|
81 |
|
82 |
+
# Build Docker image locally
|
83 |
+
echo "Building Docker image..."
|
84 |
+
# docker build -t $DOCKER_NAME .
|
85 |
+
docker build --build-arg HF_TOKEN=$HF_TOKEN -t $DOCKER_NAME .
|
86 |
|
87 |
+
# Save the Docker image to a tar file
|
88 |
+
docker save -o $DOCKER_NAME.tar $DOCKER_NAME
|
|
|
89 |
|
90 |
+
# Copy the Docker image tar to the server
|
91 |
+
echo "Copying Docker image to the server..."
|
92 |
+
scp -i "$old_ssh_key_name" -P "$PORT" $DOCKER_NAME.tar "$USER@$HOST:/home/$USER/"
|
93 |
|
94 |
+
# Load the Docker image on the server
|
95 |
+
$SSH_CONNECTION "docker load -i /home/$USER/$DOCKER_NAME.tar"
|
96 |
|
97 |
+
# Run the Docker container on the server with restart policy
|
98 |
+
$SSH_CONNECTION "docker run -d --restart unless-stopped -p 5000:5000 $DOCKER_NAME"
|
|
|
99 |
|
100 |
+
# Clean up the Docker image tar file
|
101 |
+
$SSH_CONNECTION "rm /home/$USER/$DOCKER_NAME.tar"
|
|
|
102 |
|
103 |
+
echo "Docker container is running on the server."
|