Upload 2 files
Browse files
Modelfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This tells Ollama to pull your model directly from Hugging Face Hub
|
| 2 |
+
FROM ./krishna_choudhary/AI_Assistant_Chatbot:latest
|
| 3 |
+
|
| 4 |
+
TEMPLATE """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
|
| 5 |
+
|
| 6 |
+
{{ .System }}<|eot_id|><|start_header_id|>user<|end_header_id|>
|
| 7 |
+
|
| 8 |
+
{{ .Prompt }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
|
| 9 |
+
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
PARAMETER stop "<|start_header_id|>"
|
| 13 |
+
PARAMETER stop "<|end_header_id|>"
|
| 14 |
+
PARAMETER stop "<|eot_id|>"
|
| 15 |
+
PARAMETER stop "<|end_of_text|>"
|
| 16 |
+
|
| 17 |
+
# This single line is crucial for catching all reserved tokens
|
| 18 |
+
PARAMETER stop "<|reserved_special_token_"
|
| 19 |
+
|
| 20 |
+
PARAMETER stop "\n<|start_header_id|>user"
|
| 21 |
+
PARAMETER stop "\n<|start_header_id|>assistant"
|
| 22 |
+
PARAMETER stop "user"
|
| 23 |
+
PARAMETER stop "assistant"
|
| 24 |
+
|
| 25 |
+
SYSTEM """You are a GUVI chatbot, acting as customer care. You will solve customer queries with a polite and helpful tone.
|
| 26 |
+
You are available 24/7 to assist.
|
| 27 |
+
If the customer provides any numbers (e.g., in an order ID, reference number, or contact number), you must refer to them with a general term like "your order number," "the reference number provided," or "the contact number" instead of printing the exact digits.
|
| 28 |
+
Crucially, **do NOT output any internal thoughts, debugging information, or special tokens**. Ensure your response ends cleanly, specifically avoiding tokens such as <|reserved_special_token_XXX|> (where XXX is any number).
|
| 29 |
+
"""
|
start.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Do NOT export HOME here. Let the system manage HOME for the 'appuser'
|
| 4 |
+
# (which will be /home/appuser due to the Dockerfile change).
|
| 5 |
+
# Ollama will try to write to /home/appuser/.ollama if it falls back on HOME.
|
| 6 |
+
|
| 7 |
+
# Define OLLAMA_HOME explicitly for the runtime environment in start.sh.
|
| 8 |
+
# This ensures Ollama uses /app/.ollama for its primary data, which is within the /app
|
| 9 |
+
# directory owned by 'appuser'.
|
| 10 |
+
export OLLAMA_HOME="/app/.ollama"
|
| 11 |
+
|
| 12 |
+
# Create the Ollama home directory if it doesn't exist.
|
| 13 |
+
# The Dockerfile's chown ensures 'appuser' owns /app, so 'appuser' can
|
| 14 |
+
# create this directory without permission issues.
|
| 15 |
+
mkdir -p "${OLLAMA_HOME}"
|
| 16 |
+
|
| 17 |
+
echo "Starting Ollama server..."
|
| 18 |
+
# Start Ollama server in the background.
|
| 19 |
+
# Redirect its output to a log file within OLLAMA_HOME, and also to stdout (Hugging Face Space logs).
|
| 20 |
+
/usr/local/bin/ollama serve > "${OLLAMA_HOME}/ollama.log" 2>&1 &
|
| 21 |
+
|
| 22 |
+
# Give Ollama a moment to write logs before tailing.
|
| 23 |
+
# This helps ensure `tail -f` has content to display immediately.
|
| 24 |
+
sleep 2
|
| 25 |
+
|
| 26 |
+
# Tail the Ollama log file in the background so its contents appear in the Space logs.
|
| 27 |
+
# This is crucial for debugging Ollama's internal startup process.
|
| 28 |
+
tail -f "${OLLAMA_HOME}/ollama.log" &
|
| 29 |
+
|
| 30 |
+
echo "Waiting for Ollama server to start..."
|
| 31 |
+
attempt_num=0
|
| 32 |
+
max_attempts=60 # Increased timeout to 60 seconds (60 attempts * 1 second sleep)
|
| 33 |
+
while ! curl -s http://localhost:11434/api/tags > /dev/null; do
|
| 34 |
+
if [ $attempt_num -ge $max_attempts ]; then
|
| 35 |
+
echo "Error: Ollama server failed to start after multiple attempts."
|
| 36 |
+
echo "Ollama logs:"
|
| 37 |
+
# Print the full Ollama log if it fails to start for final debugging.
|
| 38 |
+
cat "${OLLAMA_HOME}/ollama.log"
|
| 39 |
+
exit 1 # Exit with an error to signal failure to Hugging Face Spaces.
|
| 40 |
+
fi
|
| 41 |
+
echo "Ollama server not yet ready, waiting... ($((attempt_num + 1))/$max_attempts)"
|
| 42 |
+
sleep 1
|
| 43 |
+
attempt_num=$((attempt_num + 1))
|
| 44 |
+
done
|
| 45 |
+
|
| 46 |
+
echo "Ollama server is ready!"
|
| 47 |
+
echo "Starting Streamlit app..."
|
| 48 |
+
|
| 49 |
+
# Run the Streamlit application.
|
| 50 |
+
# --server.port and --server.address are essential for Docker environments
|
| 51 |
+
# to ensure Streamlit listens correctly and is accessible via Hugging Face Spaces.
|
| 52 |
+
streamlit run src/streamlit_app.py --server.port 8501 --server.address 0.0.0.0
|