yuvrajsingh6 commited on
Commit
4ba4b25
·
1 Parent(s): 71ba219

fix: Fix module imports and paths for HF Spaces

Browse files
Dockerfile CHANGED
@@ -14,12 +14,10 @@ COPY backend/requirements.txt .
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
  COPY backend/ ./backend/
17
- COPY frontend/ ./frontend/
18
-
19
- RUN cd frontend && npm install && npm run build
20
 
21
  RUN mkdir -p /app/storage/uploads /app/storage/vector_db
22
 
23
  EXPOSE 7860
24
 
25
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
  COPY backend/ ./backend/
17
+ COPY frontend/dist ./frontend/dist
 
 
18
 
19
  RUN mkdir -p /app/storage/uploads /app/storage/vector_db
20
 
21
  EXPOSE 7860
22
 
23
+ CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"]
backend/app/api/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
- from app.api.v1 import api_router
2
 
3
  __all__ = ["api_router"]
 
1
+ from backend.app.api.v1 import api_router
2
 
3
  __all__ = ["api_router"]
backend/app/api/v1/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
  from fastapi import APIRouter
2
- from app.api.v1.routes import router
3
 
4
  api_router = APIRouter()
5
  api_router.include_router(router, prefix="/v1")
 
1
  from fastapi import APIRouter
2
+ from backend.app.api.v1.routes import router
3
 
4
  api_router = APIRouter()
5
  api_router.include_router(router, prefix="/v1")
backend/app/api/v1/routes/documents.py CHANGED
@@ -1,6 +1,6 @@
1
  from fastapi import APIRouter
2
- from app.models.schemas import DocumentListResponse, Document
3
- from app.services.vector_store import vector_store
4
  from pathlib import Path
5
  from datetime import datetime
6
  import json
 
1
  from fastapi import APIRouter
2
+ from backend.app.models.schemas import DocumentListResponse, Document
3
+ from backend.app.services.vector_store import vector_store
4
  from pathlib import Path
5
  from datetime import datetime
6
  import json
backend/app/api/v1/routes/health.py CHANGED
@@ -1,5 +1,5 @@
1
  from fastapi import APIRouter
2
- from app.models.schemas import HealthResponse
3
 
4
  router = APIRouter(prefix="/health", tags=["health"])
5
 
 
1
  from fastapi import APIRouter
2
+ from backend.app.models.schemas import HealthResponse
3
 
4
  router = APIRouter(prefix="/health", tags=["health"])
5
 
backend/app/api/v1/routes/query.py CHANGED
@@ -1,9 +1,9 @@
1
  from fastapi import APIRouter, HTTPException
2
- from app.models.schemas import QueryRequest, QueryResponse
3
- from app.services.retriever import retriever_service
4
- from app.services.enhanced_llm import enhanced_llm_service
5
- from app.services.prompt_guard import prompt_guard
6
- from app.services.confidence import confidence_service
7
  from datetime import datetime
8
  import time
9
 
 
1
  from fastapi import APIRouter, HTTPException
2
+ from backend.app.models.schemas import QueryRequest, QueryResponse
3
+ from backend.app.services.retriever import retriever_service
4
+ from backend.app.services.enhanced_llm import enhanced_llm_service
5
+ from backend.app.services.prompt_guard import prompt_guard
6
+ from backend.app.services.confidence import confidence_service
7
  from datetime import datetime
8
  import time
9
 
backend/app/api/v1/routes/upload.py CHANGED
@@ -1,8 +1,8 @@
1
  from fastapi import APIRouter, UploadFile, File, HTTPException
2
- from app.models.schemas import UploadResponse
3
- from app.services.pdf_processor import pdf_processor
4
- from app.services.embeddings import embedding_service
5
- from app.services.vector_store import vector_store
6
  from pathlib import Path
7
  import uuid
8
  from datetime import datetime
 
1
  from fastapi import APIRouter, UploadFile, File, HTTPException
2
+ from backend.app.models.schemas import UploadResponse
3
+ from backend.app.services.pdf_processor import pdf_processor
4
+ from backend.app.services.embeddings import embedding_service
5
+ from backend.app.services.vector_store import vector_store
6
  from pathlib import Path
7
  import uuid
8
  from datetime import datetime
backend/app/config.py CHANGED
@@ -3,7 +3,8 @@ from pathlib import Path
3
  from dotenv import load_dotenv
4
  from pydantic import BaseModel
5
 
6
- load_dotenv()
 
7
 
8
 
9
  class Settings(BaseModel):
@@ -39,6 +40,7 @@ class Settings(BaseModel):
39
  CORS_ORIGINS: list = [
40
  "http://localhost:3000",
41
  "http://localhost:5173",
 
42
  "https://yuvis-web-based-rag.hf.space",
43
  "https://*.hf.space",
44
  ]
 
3
  from dotenv import load_dotenv
4
  from pydantic import BaseModel
5
 
6
+ env_path = Path(__file__).parent.parent / ".env"
7
+ load_dotenv(dotenv_path=str(env_path))
8
 
9
 
10
  class Settings(BaseModel):
 
40
  CORS_ORIGINS: list = [
41
  "http://localhost:3000",
42
  "http://localhost:5173",
43
+ "http://localhost:5175",
44
  "https://yuvis-web-based-rag.hf.space",
45
  "https://*.hf.space",
46
  ]
backend/app/main.py CHANGED
@@ -2,13 +2,13 @@ from fastapi import FastAPI
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.staticfiles import StaticFiles
4
  from fastapi.responses import FileResponse
5
- from app.api.v1.routes import router as api_router
6
- from app.config import settings
7
  import os
8
 
9
  app = FastAPI(
10
  title="RAG System API",
11
- description="Production-grade RAG system with PDF and web search",
12
  version="1.0.0",
13
  docs_url="/api/docs",
14
  redoc_url="/api/redoc",
@@ -25,14 +25,12 @@ app.add_middleware(
25
  app.include_router(api_router, prefix="/api/v1")
26
 
27
  # Serve static files (React frontend)
28
- frontend_path = "/app"
29
  try:
30
- app.mount("/", StaticFiles(directory=frontend_path, html=True), name="static")
31
- except RuntimeError:
32
- # Fallback path if /app doesn't exist
33
- fallback_path = os.path.join(os.path.dirname(__file__), "../../frontend/dist")
34
- if os.path.exists(fallback_path):
35
- app.mount("/", StaticFiles(directory=fallback_path, html=True), name="static")
36
 
37
 
38
  @app.get("/")
@@ -40,10 +38,6 @@ async def serve_index():
40
  index_path = os.path.join(frontend_path, "index.html")
41
  if os.path.exists(index_path):
42
  return FileResponse(index_path)
43
- # Also try fallback path
44
- fallback_path = os.path.join(os.path.dirname(__file__), "../../frontend/dist/index.html")
45
- if os.path.exists(fallback_path):
46
- return FileResponse(fallback_path)
47
  return {"message": "RAG System API", "version": "1.0.0"}
48
 
49
 
 
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.staticfiles import StaticFiles
4
  from fastapi.responses import FileResponse
5
+ from backend.app.api.v1.routes import router as api_router
6
+ from backend.app.config import settings
7
  import os
8
 
9
  app = FastAPI(
10
  title="RAG System API",
11
+ description="Production-grade RAG system with PDF document processing and web search",
12
  version="1.0.0",
13
  docs_url="/api/docs",
14
  redoc_url="/api/redoc",
 
25
  app.include_router(api_router, prefix="/api/v1")
26
 
27
  # Serve static files (React frontend)
28
+ frontend_path = os.path.join(os.path.dirname(__file__), "../../frontend/dist")
29
  try:
30
+ if os.path.exists(frontend_path):
31
+ app.mount("/", StaticFiles(directory=frontend_path, html=True), name="static")
32
+ except Exception:
33
+ pass
 
 
34
 
35
 
36
  @app.get("/")
 
38
  index_path = os.path.join(frontend_path, "index.html")
39
  if os.path.exists(index_path):
40
  return FileResponse(index_path)
 
 
 
 
41
  return {"message": "RAG System API", "version": "1.0.0"}
42
 
43
 
backend/app/services/confidence.py CHANGED
@@ -1,6 +1,6 @@
1
  from typing import List
2
- from app.models.schemas import Source
3
- from app.services.embeddings import embedding_service
4
 
5
 
6
  class ConfidenceService:
 
1
  from typing import List
2
+ from backend.app.models.schemas import Source
3
+ from backend.app.services.embeddings import embedding_service
4
 
5
 
6
  class ConfidenceService:
backend/app/services/embeddings.py CHANGED
@@ -1,7 +1,7 @@
1
  from sentence_transformers import SentenceTransformer
2
  from typing import List
3
  import numpy as np
4
- from app.config import settings
5
 
6
 
7
  class EmbeddingService:
 
1
  from sentence_transformers import SentenceTransformer
2
  from typing import List
3
  import numpy as np
4
+ from backend.app.config import settings
5
 
6
 
7
  class EmbeddingService:
backend/app/services/enhanced_llm.py CHANGED
@@ -16,8 +16,8 @@ from datetime import datetime
16
  from dataclasses import dataclass
17
  from enum import Enum
18
 
19
- from app.models.schemas import Source
20
- from app.config import settings
21
 
22
 
23
  class ModelType(Enum):
 
16
  from dataclasses import dataclass
17
  from enum import Enum
18
 
19
+ from backend.app.models.schemas import Source
20
+ from backend.app.config import settings
21
 
22
 
23
  class ModelType(Enum):
backend/app/services/llm_service.py CHANGED
@@ -2,8 +2,8 @@ import aiohttp
2
  import asyncio
3
  import time
4
  from typing import List
5
- from app.models.schemas import Source
6
- from app.config import settings
7
 
8
 
9
  class LLMService:
 
2
  import asyncio
3
  import time
4
  from typing import List
5
+ from backend.app.models.schemas import Source
6
+ from backend.app.config import settings
7
 
8
 
9
  class LLMService:
backend/app/services/pdf_processor.py CHANGED
@@ -2,7 +2,7 @@ import pypdf
2
  import pdfplumber
3
  from pathlib import Path
4
  from typing import List, Tuple
5
- from app.utils.chunking import intelligent_chunk, create_chunk_metadata
6
 
7
 
8
  class PDFProcessor:
 
2
  import pdfplumber
3
  from pathlib import Path
4
  from typing import List, Tuple
5
+ from backend.app.utils.chunking import intelligent_chunk, create_chunk_metadata
6
 
7
 
8
  class PDFProcessor:
backend/app/services/retriever.py CHANGED
@@ -1,8 +1,8 @@
1
  from typing import List, Dict, Optional
2
- from app.services.embeddings import embedding_service
3
- from app.services.vector_store import vector_store
4
- from app.services.web_search import web_search_service
5
- from app.models.schemas import Source, SourceType, QueryMode
6
 
7
 
8
  class RetrieverService:
 
1
  from typing import List, Dict, Optional
2
+ from backend.app.services.embeddings import embedding_service
3
+ from backend.app.services.vector_store import vector_store
4
+ from backend.app.services.web_search import web_search_service
5
+ from backend.app.models.schemas import Source, SourceType, QueryMode
6
 
7
 
8
  class RetrieverService:
backend/app/services/vector_store.py CHANGED
@@ -2,7 +2,7 @@ import chromadb
2
  from chromadb.config import Settings as ChromaSettings
3
  from typing import List, Dict, Optional
4
  from pathlib import Path
5
- from app.config import settings
6
 
7
 
8
  class VectorStore:
 
2
  from chromadb.config import Settings as ChromaSettings
3
  from typing import List, Dict, Optional
4
  from pathlib import Path
5
+ from backend.app.config import settings
6
 
7
 
8
  class VectorStore:
backend/app/services/web_search.py CHANGED
@@ -16,7 +16,7 @@ from dataclasses import dataclass
16
  from enum import Enum
17
  import json
18
 
19
- from app.config import settings
20
 
21
 
22
  class SearchProvider(Enum):
 
16
  from enum import Enum
17
  import json
18
 
19
+ from backend.app.config import settings
20
 
21
 
22
  class SearchProvider(Enum):