Refactor Dockerfile for improved caching and add health check endpoint
Browse files- Dockerfile +13 -7
- app.py +5 -0
- data_snapshot/chat_history/chat_history_2025-03-14.json +14 -0
- space.yaml +2 -1
Dockerfile
CHANGED
@@ -12,21 +12,22 @@ RUN mkdir -p cache/huggingface vector_store chat_history \
|
|
12 |
&& chown -R 1000:1000 . \
|
13 |
&& chmod -R 755 .
|
14 |
|
15 |
-
# Copy
|
16 |
COPY requirements.txt .
|
17 |
-
|
18 |
-
# Install Python dependencies
|
19 |
RUN pip install --no-cache-dir -r requirements.txt
|
20 |
|
21 |
-
# Copy
|
22 |
-
COPY . .
|
|
|
|
|
23 |
|
24 |
# Set environment variables
|
25 |
ENV HF_HOME=/app/cache/huggingface
|
26 |
ENV HUGGINGFACE_HUB_CACHE=/app/cache/huggingface
|
27 |
ENV XDG_CACHE_HOME=/app/cache
|
|
|
28 |
|
29 |
-
# Set permissions
|
30 |
RUN chown -R 1000:1000 /app \
|
31 |
&& find /app -type d -exec chmod 755 {} \; \
|
32 |
&& find /app -type f -exec chmod 644 {} \;
|
@@ -34,6 +35,11 @@ RUN chown -R 1000:1000 /app \
|
|
34 |
# Run as non-privileged user
|
35 |
USER 1000
|
36 |
|
|
|
|
|
|
|
|
|
37 |
EXPOSE 8000
|
38 |
|
39 |
-
|
|
|
|
12 |
&& chown -R 1000:1000 . \
|
13 |
&& chmod -R 755 .
|
14 |
|
15 |
+
# Copy requirements first for better caching
|
16 |
COPY requirements.txt .
|
|
|
|
|
17 |
RUN pip install --no-cache-dir -r requirements.txt
|
18 |
|
19 |
+
# Copy only necessary files
|
20 |
+
COPY app.py .
|
21 |
+
COPY .env .
|
22 |
+
COPY index.html .
|
23 |
|
24 |
# Set environment variables
|
25 |
ENV HF_HOME=/app/cache/huggingface
|
26 |
ENV HUGGINGFACE_HUB_CACHE=/app/cache/huggingface
|
27 |
ENV XDG_CACHE_HOME=/app/cache
|
28 |
+
ENV PORT=8000
|
29 |
|
30 |
+
# Set permissions
|
31 |
RUN chown -R 1000:1000 /app \
|
32 |
&& find /app -type d -exec chmod 755 {} \; \
|
33 |
&& find /app -type f -exec chmod 644 {} \;
|
|
|
35 |
# Run as non-privileged user
|
36 |
USER 1000
|
37 |
|
38 |
+
# Health check
|
39 |
+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
40 |
+
CMD curl -f http://localhost:8000/health || exit 1
|
41 |
+
|
42 |
EXPOSE 8000
|
43 |
|
44 |
+
# Use a startup script
|
45 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--timeout-keep-alive", "120"]
|
app.py
CHANGED
@@ -314,6 +314,11 @@ async def root():
|
|
314 |
"kb_info": kb_info if vector_store_exists else None
|
315 |
}
|
316 |
|
|
|
|
|
|
|
|
|
|
|
317 |
@app.post("/build-kb", response_model=BuildKnowledgeBaseResponse)
|
318 |
async def build_kb_endpoint():
|
319 |
"""Endpoint to build/rebuild the knowledge base"""
|
|
|
314 |
"kb_info": kb_info if vector_store_exists else None
|
315 |
}
|
316 |
|
317 |
+
@app.get("/health")
|
318 |
+
async def health_check():
|
319 |
+
"""Health check endpoint"""
|
320 |
+
return {"status": "healthy"}
|
321 |
+
|
322 |
@app.post("/build-kb", response_model=BuildKnowledgeBaseResponse)
|
323 |
async def build_kb_endpoint():
|
324 |
"""Endpoint to build/rebuild the knowledge base"""
|
data_snapshot/chat_history/chat_history_2025-03-14.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"timestamp": "2025-03-14 09:27:01",
|
4 |
+
"question": "where are you located?",
|
5 |
+
"answer": "Hello, I'm happy to help. Status Law is an international law firm specializing in extradition cases, with a presence in the European Union. Our team of multilingual lawyers has on-the-ground experience in key regions, providing us with a network of international connections that supports our operations outside the EU. We have expertise in various practice areas, including extradition defense, international prosecution protection, and Interpol red notice removal. If you have any specific questions or need more information, please don't hesitate to contact us via phone at +32465594521 or through our contact form: https://status.law/law-firm-contact-legal-protection/.",
|
6 |
+
"context": "Minimum 5 working hours, transportation and accommodation apply for specialist deployments\n\n\n\n\nLocal attorneys' fees are charged separately\n\n\n\n\nDocument translation and legalization costs are not included\nPractice Areas - Status Law HomeServicesExtradition defenseInternational prosecution protectionInterpol red notice removalCross-border banking legal issuesReputation protectionChallenging sanctionsAbout UsRegions of operationsCareersFAQContactOur PricingEnglishEnglishРусскийEspañolالعربية中文 (中国)\nInterpol red notice removal | Status.Law HomeServicesExtradition defenseInternational prosecution protectionInterpol red notice removalCross-border banking legal issuesReputation protectionChallenging sanctionsAbout UsRegions of operationsCareersFAQContactOur PricingEnglishEnglishРусскийEspañolالعربية中文 (中国)\nof each of the distinct areas our clients are coming from. Each of the practices is supervised by one of our attorneys who has resided and practiced law in the respective region before relocating to the EU. In addition to the in-depth knowledge of the peculiarities of local law, processes and institutions this provides us with a network of international connections that supports our operations outside the European Union.Our team of multilingual lawyers with on-the-ground experience in key"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"timestamp": "2025-03-14 10:47:51",
|
10 |
+
"question": "How much does a 1 hour consultation cost?",
|
11 |
+
"answer": "Our initial consultation is designed to help clients resolve their situation efficiently, and it often makes further cooperation unnecessary. The cost of the consultation reflects its potential to provide a comprehensive solution. For specific pricing details, please visit our Services and Pricing page: https://status.law/tariffs-for-services-against-extradition-en. If you have any further questions or would like to book a consultation, feel free to contact us via phone at +32465594521 or use our contact form: https://status.law/law-firm-contact-legal-protection/.",
|
12 |
+
"context": "It often happens that an initial consultation helps clients to resolve their situation and makes further cooperation unnecessary, which explains its relatively high cost.Are there any services you can provide on a pro bono basis?Our lawyers consult a limited number of qualified government and NGO bodies on matters of human rights violations and the imposition of sanctions. Please contact us for further details.I cannot visit you in person or call you due to privacy concerns. Can I get your\nMinimum 5 working hours, transportation and accommodation apply for specialist deployments\n\n\n\n\nLocal attorneys' fees are charged separately\n\n\n\n\nDocument translation and legalization costs are not included\nDocument translation and legalization costs are not included\n\n\n\n\nSuccess fees apply only for positive outcomesAll information on the “Status Law” Law Firm’s website is for informational purposes only, does not constitute legal advice or recommendations, and does not establish an attorney-client relationship between the user and the firm.You can book a consultation time using the quick form below or by going to our contact page here.\nlegal advice.MAKE A REQUESTPartners and EmployeesOur lawyers are highly skilled and accessible, get personal attention to every matterPawel Leszek KazaneckiSpecialist in democratic development and human rights."
|
13 |
+
}
|
14 |
+
]
|
space.yaml
CHANGED
@@ -6,4 +6,5 @@ colorTo: indigo
|
|
6 |
sdk_version: 0.0.1
|
7 |
app_port: 8000
|
8 |
pinned: false
|
9 |
-
license: mit
|
|
|
|
6 |
sdk_version: 0.0.1
|
7 |
app_port: 8000
|
8 |
pinned: false
|
9 |
+
license: mit
|
10 |
+
startup_duration: 900
|