yassinekolsi commited on
Commit
e87fea1
·
1 Parent(s): 5770d80

Deploy to HuggingFace Spaces

Browse files
.env.example ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ==============================================
2
+ # BACKEND CONFIGURATION (Hugging Face / Local)
3
+ # ==============================================
4
+
5
+ # Qdrant Cloud Credentials
6
+ # Get these from https://cloud.qdrant.io
7
+ # If running locally with Docker, use: http://localhost:6333 and leave API_KEY empty
8
+ QDRANT_URL=https://your-cluster-id.region.qdrant.tech
9
+ QDRANT_API_KEY=your-super-secret-api-key-here
10
+
11
+ # Qdrant Settings (Optional)
12
+ # QDRANT_COLLECTION=bio_discovery
13
+
14
+ # ==============================================
15
+ # FRONTEND CONFIGURATION (Vercel / Local)
16
+ # ==============================================
17
+ # NOTE: For Next.js (Vercel), these usually go in ui/.env.local or Vercel Dashboard
18
+
19
+ # The URL where your Backend is running
20
+ # Local: http://localhost:8000
21
+ # Production (Hugging Face): https://your-space-name.hf.space
22
+ NEXT_PUBLIC_API_URL=http://localhost:8000
23
+
24
+ # The URL where your Frontend is running
25
+ # Local: http://localhost:3000
26
+ # Production (Vercel): https://your-project.vercel.app
27
+ NEXT_PUBLIC_APP_URL=http://localhost:3000
Dockerfile.hf ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a lightweight python image
2
+ FROM python:3.9-slim
3
+
4
+ # Set environment variables
5
+ ENV PYTHONDONTWRITEBYTECODE=1 \
6
+ PYTHONUNBUFFERED=1 \
7
+ DEBIAN_FRONTEND=noninteractive
8
+
9
+ # Install system dependencies required for RDKit and build tools
10
+ RUN apt-get update && apt-get install -y \
11
+ libxrender1 \
12
+ libxext6 \
13
+ build-essential \
14
+ wget \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # Set working directory
18
+ WORKDIR /app
19
+
20
+ # Upgrade pip
21
+ RUN pip install --no-cache-dir --upgrade pip
22
+
23
+ # Copy only requirements first to cache dependencies
24
+ COPY requirements.txt .
25
+
26
+ # Install dependencies
27
+ # Using automatic cpu version for torch to keep image small
28
+ RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu
29
+ RUN pip install --no-cache-dir -r requirements.txt
30
+
31
+ # Copy the rest of the application
32
+ COPY . .
33
+
34
+ # Expose the API port
35
+ EXPOSE 8000
36
+
37
+ # Create a non-root user for security (good practice for HF Spaces)
38
+ RUN useradd -m -u 1000 user
39
+ USER user
40
+ ENV HOME=/home/user \
41
+ PATH=/home/user/.local/bin:$PATH
42
+
43
+ # Command to run the application
44
+ CMD ["uvicorn", "bioflow.api.server:app", "--host", "0.0.0.0", "--port", "8000"]
bioflow/api/qdrant_service.py CHANGED
@@ -88,6 +88,7 @@ class QdrantService:
88
  self,
89
  model_service=None,
90
  url: str = None,
 
91
  path: str = None,
92
  vector_dim: int = 768
93
  ):
@@ -97,6 +98,7 @@ class QdrantService:
97
  Args:
98
  model_service: ModelService for embeddings
99
  url: Qdrant server URL (e.g., http://localhost:6333)
 
100
  path: Path for local Qdrant storage
101
  vector_dim: Dimension of embedding vectors
102
 
@@ -105,6 +107,7 @@ class QdrantService:
105
  """
106
  self.model_service = model_service
107
  self.url = url or os.getenv("QDRANT_URL")
 
108
  self.path = path or os.getenv("QDRANT_PATH", "./qdrant_data")
109
  self.vector_dim = vector_dim
110
  self.hnsw_m = int(os.getenv("QDRANT_HNSW_M", "16"))
@@ -143,7 +146,7 @@ class QdrantService:
143
  from qdrant_client import QdrantClient
144
 
145
  if self.url:
146
- self._client = QdrantClient(url=self.url)
147
  logger.info(f"Connected to Qdrant at {self.url}")
148
  else:
149
  self._client = QdrantClient(path=self.path)
 
88
  self,
89
  model_service=None,
90
  url: str = None,
91
+ api_key: str = None,
92
  path: str = None,
93
  vector_dim: int = 768
94
  ):
 
98
  Args:
99
  model_service: ModelService for embeddings
100
  url: Qdrant server URL (e.g., http://localhost:6333)
101
+ api_key: Qdrant API key for cloud clusters
102
  path: Path for local Qdrant storage
103
  vector_dim: Dimension of embedding vectors
104
 
 
107
  """
108
  self.model_service = model_service
109
  self.url = url or os.getenv("QDRANT_URL")
110
+ self.api_key = api_key or os.getenv("QDRANT_API_KEY")
111
  self.path = path or os.getenv("QDRANT_PATH", "./qdrant_data")
112
  self.vector_dim = vector_dim
113
  self.hnsw_m = int(os.getenv("QDRANT_HNSW_M", "16"))
 
146
  from qdrant_client import QdrantClient
147
 
148
  if self.url:
149
+ self._client = QdrantClient(url=self.url, api_key=self.api_key)
150
  logger.info(f"Connected to Qdrant at {self.url}")
151
  else:
152
  self._client = QdrantClient(path=self.path)
requirements.txt CHANGED
@@ -20,3 +20,5 @@ scanpy==1.10.3
20
  qdrant-client>=1.7.0
21
  plotly>=5.18.0
22
  scikit-learn>=1.3.0
 
 
 
20
  qdrant-client>=1.7.0
21
  plotly>=5.18.0
22
  scikit-learn>=1.3.0
23
+
24
+ torch>=2.0.0
server/api.py CHANGED
@@ -36,9 +36,10 @@ from config import (
36
  app = FastAPI(title="BioDiscovery API", version="2.0")
37
 
38
  # CORS for frontend
 
39
  app.add_middleware(
40
  CORSMiddleware,
41
- allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],
42
  allow_methods=["*"],
43
  allow_headers=["*"],
44
  )
 
36
  app = FastAPI(title="BioDiscovery API", version="2.0")
37
 
38
  # CORS for frontend
39
+ # Allow generic access for deployment - in production restrict this to your Vercel domain
40
  app.add_middleware(
41
  CORSMiddleware,
42
+ allow_origins=["*"],
43
  allow_methods=["*"],
44
  allow_headers=["*"],
45
  )