Spaces:
Runtime error
Runtime error
russkiyximik commited on
Commit ·
ba5504b
1
Parent(s): 67cca4b
migrate to docker sdk attempt
Browse files- README.md +3 -4
- mycoder/Dockerfile +32 -0
- mycoder/app.py +1 -6
- mycoder/entrypoint.sh +17 -0
- mycoder/src/inner/ollama_utils.py +0 -13
README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: "🧬"
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: blue
|
| 6 |
-
sdk:
|
| 7 |
sdk_version: 1.41.0
|
| 8 |
python_version: "3.12"
|
| 9 |
-
|
| 10 |
-
pinned: false
|
| 11 |
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: query2plot-demo
|
| 3 |
emoji: "🧬"
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
sdk_version: 1.41.0
|
| 8 |
python_version: "3.12"
|
| 9 |
+
app_port: 7860
|
|
|
|
| 10 |
---
|
mycoder/Dockerfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM ollama/ollama:latest
|
| 2 |
+
|
| 3 |
+
# Create a user and set up permissions
|
| 4 |
+
RUN useradd -ms /bin/bash ollama-user
|
| 5 |
+
|
| 6 |
+
# Set the home directory
|
| 7 |
+
ENV HOME=/home/ollama-user
|
| 8 |
+
WORKDIR $HOME
|
| 9 |
+
|
| 10 |
+
# Ensure the user has access to the directory
|
| 11 |
+
RUN mkdir -p $HOME/.ollama && chown -R ollama-user:ollama-user $HOME/.ollama
|
| 12 |
+
|
| 13 |
+
# Install netcat (nc) for checking server readiness
|
| 14 |
+
RUN apt-get update && apt-get install -y netcat
|
| 15 |
+
|
| 16 |
+
# Copy the entrypoint script before switching users
|
| 17 |
+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 18 |
+
|
| 19 |
+
# Set permissions for the entrypoint script
|
| 20 |
+
RUN chmod +x /usr/local/bin/entrypoint.sh
|
| 21 |
+
|
| 22 |
+
# Switch to the non-root user
|
| 23 |
+
USER ollama-user
|
| 24 |
+
|
| 25 |
+
# Set Ollama to listen on all network interfaces
|
| 26 |
+
ENV OLLAMA_HOST=0.0.0.0:7860
|
| 27 |
+
|
| 28 |
+
# Expose the default port
|
| 29 |
+
EXPOSE 7860
|
| 30 |
+
|
| 31 |
+
# Use the custom entrypoint script
|
| 32 |
+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
mycoder/app.py
CHANGED
|
@@ -33,9 +33,4 @@ if st.button("Run Query2Plot"):
|
|
| 33 |
|
| 34 |
# TO DO: Display the generated plot if it exists
|
| 35 |
if os.path.exists("output/plot.png"):
|
| 36 |
-
st.image("output/plot.png", caption="Generated Figure")
|
| 37 |
-
|
| 38 |
-
if st.button("Test Ollama Server"):
|
| 39 |
-
from mycoder.src.inner.ollama_utils import download_ollama, start_ollama, start_model, stop_model
|
| 40 |
-
download_ollama()
|
| 41 |
-
start_ollama()
|
|
|
|
| 33 |
|
| 34 |
# TO DO: Display the generated plot if it exists
|
| 35 |
if os.path.exists("output/plot.png"):
|
| 36 |
+
st.image("output/plot.png", caption="Generated Figure")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mycoder/entrypoint.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Start Ollama server in the background
|
| 4 |
+
ollama serve &
|
| 5 |
+
|
| 6 |
+
# Wait for the server to be ready
|
| 7 |
+
while ! nc -z localhost 7860; do
|
| 8 |
+
echo "Waiting for Ollama server to start..."
|
| 9 |
+
sleep 1
|
| 10 |
+
done
|
| 11 |
+
|
| 12 |
+
# Pull the model
|
| 13 |
+
echo "Pulling the model..."
|
| 14 |
+
ollama pull gemma3:1b
|
| 15 |
+
|
| 16 |
+
# Keep the container running
|
| 17 |
+
wait
|
mycoder/src/inner/ollama_utils.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
import subprocess
|
| 2 |
-
|
| 3 |
-
def download_ollama() -> None:
|
| 4 |
-
subprocess.run(["curl -fsSL https://ollama.com/install.sh | sh"], shell=True, check=True)
|
| 5 |
-
|
| 6 |
-
def start_ollama() -> None:
|
| 7 |
-
subprocess.run(["ollama", "serve"], shell=True, check=True)
|
| 8 |
-
|
| 9 |
-
def start_model() -> None:
|
| 10 |
-
subprocess.run(["ollama", "run", "codellama:7b"], check=True)
|
| 11 |
-
|
| 12 |
-
def stop_model() -> None:
|
| 13 |
-
subprocess.run(["ollama", "stop", "codellama:7b"], check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|