Spaces:
Sleeping
Sleeping
n0v33n
commited on
Commit
·
1b4bba1
1
Parent(s):
dff783c
Fix cache permissions
Browse files- Dockerfile +26 -3
- app.py +12 -3
- requirements.txt +31 -17
- tools.py +7 -0
Dockerfile
CHANGED
@@ -1,20 +1,43 @@
|
|
1 |
# Use the official Python 3.12 slim image
|
2 |
FROM python:3.12-slim
|
|
|
3 |
# Set working directory
|
4 |
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# Copy and install dependencies
|
6 |
COPY requirements.txt .
|
7 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
8 |
# Copy all application files
|
9 |
COPY . .
|
|
|
|
|
|
|
|
|
10 |
# Run the FastAPI app with Uvicorn on port 7860 (required by HF Spaces)
|
11 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
12 |
|
13 |
-
|
14 |
# docker build -t precollegefastapi .
|
15 |
# docker images
|
16 |
# docker ps
|
17 |
# docker run --env-file .env -p 8080:8080 precollegefastapi
|
18 |
# docker tag precollegefastapi asura0575/precollegefastapi:latest
|
19 |
-
# docker push asura0575/precollegefastapi
|
20 |
-
|
|
|
1 |
# Use the official Python 3.12 slim image
|
2 |
FROM python:3.12-slim
|
3 |
+
|
4 |
# Set working directory
|
5 |
WORKDIR /app
|
6 |
+
|
7 |
+
# Install system dependencies
|
8 |
+
RUN apt-get update && apt-get install -y \
|
9 |
+
git \
|
10 |
+
curl \
|
11 |
+
&& rm -rf /var/lib/apt/lists/* \
|
12 |
+
&& apt-get clean
|
13 |
+
|
14 |
+
# Create cache directories with proper permissions
|
15 |
+
RUN mkdir -p /tmp/huggingface_cache /tmp/transformers_cache /tmp/datasets_cache && \
|
16 |
+
chmod -R 777 /tmp/huggingface_cache /tmp/transformers_cache /tmp/datasets_cache
|
17 |
+
|
18 |
+
# Set environment variables for cache directories
|
19 |
+
ENV HF_HOME=/tmp/huggingface_cache
|
20 |
+
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
|
21 |
+
ENV HF_DATASETS_CACHE=/tmp/datasets_cache
|
22 |
+
ENV PYTHONUNBUFFERED=1
|
23 |
+
ENV PORT=7860
|
24 |
+
|
25 |
# Copy and install dependencies
|
26 |
COPY requirements.txt .
|
27 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
28 |
+
|
29 |
# Copy all application files
|
30 |
COPY . .
|
31 |
+
|
32 |
+
# Expose the port
|
33 |
+
EXPOSE 7860
|
34 |
+
|
35 |
# Run the FastAPI app with Uvicorn on port 7860 (required by HF Spaces)
|
36 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
37 |
|
|
|
38 |
# docker build -t precollegefastapi .
|
39 |
# docker images
|
40 |
# docker ps
|
41 |
# docker run --env-file .env -p 8080:8080 precollegefastapi
|
42 |
# docker tag precollegefastapi asura0575/precollegefastapi:latest
|
43 |
+
# docker push asura0575/precollegefastapi
|
|
app.py
CHANGED
@@ -1,3 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
from fastapi import FastAPI, HTTPException
|
3 |
from pydantic import BaseModel
|
@@ -6,7 +18,6 @@ from google.adk.agents import Agent
|
|
6 |
from google.adk.sessions import InMemorySessionService
|
7 |
from google.adk.runners import Runner
|
8 |
from google.genai import types
|
9 |
-
import os
|
10 |
import re
|
11 |
from tools import (
|
12 |
db_tool,
|
@@ -15,8 +26,6 @@ from tools import (
|
|
15 |
mentor_tool,
|
16 |
add_query_to_sheet
|
17 |
)
|
18 |
-
import warnings
|
19 |
-
warnings.filterwarnings("ignore")
|
20 |
|
21 |
# === LOAD ENV ===
|
22 |
load_dotenv()
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
|
4 |
+
# === CRITICAL: Set cache directories BEFORE any other imports ===
|
5 |
+
os.environ['HF_HOME'] = '/tmp/huggingface_cache'
|
6 |
+
os.environ['TRANSFORMERS_CACHE'] = '/tmp/transformers_cache'
|
7 |
+
os.environ['HF_DATASETS_CACHE'] = '/tmp/datasets_cache'
|
8 |
+
|
9 |
+
# Suppress warnings
|
10 |
+
warnings.filterwarnings("ignore")
|
11 |
+
|
12 |
+
# Now import everything else
|
13 |
import json
|
14 |
from fastapi import FastAPI, HTTPException
|
15 |
from pydantic import BaseModel
|
|
|
18 |
from google.adk.sessions import InMemorySessionService
|
19 |
from google.adk.runners import Runner
|
20 |
from google.genai import types
|
|
|
21 |
import re
|
22 |
from tools import (
|
23 |
db_tool,
|
|
|
26 |
mentor_tool,
|
27 |
add_query_to_sheet
|
28 |
)
|
|
|
|
|
29 |
|
30 |
# === LOAD ENV ===
|
31 |
load_dotenv()
|
requirements.txt
CHANGED
@@ -1,37 +1,51 @@
|
|
1 |
# Web framework
|
2 |
-
fastapi
|
3 |
-
uvicorn[standard]
|
4 |
|
5 |
# Environment and OS
|
6 |
-
python-dotenv
|
7 |
|
8 |
# HTTP Requests
|
9 |
-
requests
|
10 |
|
11 |
# Google Sheets
|
12 |
-
gspread
|
13 |
-
|
|
|
|
|
14 |
|
15 |
# Hugging Face
|
16 |
-
huggingface_hub
|
|
|
17 |
|
18 |
# LangChain + Vector Stores
|
19 |
-
langchain
|
20 |
-
langchain-community
|
21 |
-
faiss-cpu
|
22 |
-
|
|
|
23 |
# Embeddings
|
24 |
-
sentence-transformers
|
25 |
|
26 |
# Google Generative AI (Gemini)
|
27 |
-
google-generativeai
|
28 |
|
29 |
# Tavily Search Tool
|
30 |
-
tavily-python
|
31 |
|
32 |
# JSON + Utilities
|
33 |
-
pydantic
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
-
|
|
|
|
1 |
# Web framework
|
2 |
+
fastapi==0.104.1
|
3 |
+
uvicorn[standard]==0.24.0
|
4 |
|
5 |
# Environment and OS
|
6 |
+
python-dotenv==1.0.0
|
7 |
|
8 |
# HTTP Requests
|
9 |
+
requests==2.31.0
|
10 |
|
11 |
# Google Sheets
|
12 |
+
gspread==5.12.0
|
13 |
+
# Note: oauth2client is deprecated, gspread now uses google-auth
|
14 |
+
google-auth==2.23.4
|
15 |
+
google-auth-oauthlib==1.1.0
|
16 |
|
17 |
# Hugging Face
|
18 |
+
huggingface_hub==0.19.0
|
19 |
+
transformers==4.35.0
|
20 |
|
21 |
# LangChain + Vector Stores
|
22 |
+
langchain==0.1.0
|
23 |
+
langchain-community==0.0.13
|
24 |
+
faiss-cpu==1.7.4
|
25 |
+
langchain-tavily==0.0.1
|
26 |
+
|
27 |
# Embeddings
|
28 |
+
sentence-transformers==2.2.2
|
29 |
|
30 |
# Google Generative AI (Gemini)
|
31 |
+
google-generativeai==0.3.2
|
32 |
|
33 |
# Tavily Search Tool
|
34 |
+
tavily-python==0.3.3
|
35 |
|
36 |
# JSON + Utilities
|
37 |
+
pydantic==2.5.0
|
38 |
+
|
39 |
+
# WSGI server (optional for HF Spaces since we use uvicorn)
|
40 |
+
# gunicorn==21.2.0
|
41 |
+
|
42 |
+
# Google ADK - This might be the issue!
|
43 |
+
# google-adk
|
44 |
|
45 |
+
# Additional dependencies that might be needed
|
46 |
+
numpy==1.24.3
|
47 |
+
torch==2.1.0
|
48 |
+
python-multipart==0.0.6
|
49 |
|
50 |
+
# For better error handling
|
51 |
+
tenacity==8.2.3
|
tools.py
CHANGED
@@ -1,4 +1,11 @@
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import json
|
3 |
import datetime
|
4 |
import requests
|
|
|
1 |
import os
|
2 |
+
|
3 |
+
# === CRITICAL: Set cache directories BEFORE any other imports ===
|
4 |
+
os.environ['HF_HOME'] = '/tmp/huggingface_cache'
|
5 |
+
os.environ['TRANSFORMERS_CACHE'] = '/tmp/transformers_cache'
|
6 |
+
os.environ['HF_DATASETS_CACHE'] = '/tmp/datasets_cache'
|
7 |
+
|
8 |
+
# Now import everything else
|
9 |
import json
|
10 |
import datetime
|
11 |
import requests
|