PadmasaliGovardhan commited on
Commit
59afaa2
·
1 Parent(s): f31d983

all update file adding

Browse files
Dockerfile CHANGED
@@ -1,20 +1,22 @@
1
- # Use lightweight Python image
2
  FROM python:3.10-slim
3
 
4
  WORKDIR /code
5
 
6
  # Copy dependencies first
7
  COPY app/requirements.txt /code/requirements.txt
8
-
9
- # Install dependencies
10
  RUN pip install --no-cache-dir -r /code/requirements.txt
11
 
12
- # Copy your app package
13
  COPY app /code/app
14
 
15
- # Expose port (Hugging Face uses 7860 or the platform $PORT)
 
 
 
 
 
 
16
  EXPOSE 7860
17
 
18
- # Start FastAPI using the package (no name conflict)
19
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
20
 
 
 
1
  FROM python:3.10-slim
2
 
3
  WORKDIR /code
4
 
5
  # Copy dependencies first
6
  COPY app/requirements.txt /code/requirements.txt
 
 
7
  RUN pip install --no-cache-dir -r /code/requirements.txt
8
 
 
9
  COPY app /code/app
10
 
11
+ # (Optional) Copy .env if needed
12
+ # COPY .env /code/.env
13
+
14
+ # Ensure upload/data directory exists
15
+ RUN mkdir -p /code/data/notes
16
+
17
+ # Expose app port (Hugging Face uses $PORT by default)
18
  EXPOSE 7860
19
 
20
+ # Set default CMD: Use env PORT if given, else 7860
21
+ CMD [ "sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}" ]
22
 
app/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ #hiiiiii
app/data/notes/Padmasali_Govardhan_Resume.pdf ADDED
Binary file (63.6 kB). View file
 
app/main.py CHANGED
@@ -1,14 +1,17 @@
1
- # backend/main.py
2
  from dotenv import load_dotenv
3
- load_dotenv() # loads .env file
4
 
5
  from fastapi import FastAPI, UploadFile, Form, File
6
  from fastapi.middleware.cors import CORSMiddleware
7
  import fitz
8
  import os
 
 
9
  from rag_app import RAGApp
10
 
11
  app = FastAPI(title="Personal Assistant")
 
12
  rag = RAGApp()
13
 
14
  app.add_middleware(
@@ -19,7 +22,9 @@ app.add_middleware(
19
  allow_headers=["*"],
20
  )
21
 
22
- UPLOAD_DIR = "../data/notes"
 
 
23
  os.makedirs(UPLOAD_DIR, exist_ok=True)
24
 
25
  def extract_text_from_pdf(pdf_path):
@@ -28,25 +33,24 @@ def extract_text_from_pdf(pdf_path):
28
  for page in doc:
29
  text += page.get_text()
30
  return text
31
-
32
 
33
  @app.post("/upload_pdf/")
34
  async def upload_pdf(file: UploadFile = File(...)):
35
- path = os.path.join(UPLOAD_DIR, file.filename)
 
 
36
  with open(path, "wb") as f:
37
  f.write(await file.read())
38
  text = extract_text_from_pdf(path)
39
  chunks = rag.add_notes(text)
40
- return {"status": "success", "message": f"{file.filename} Uploaded Sucessfully...."}
41
-
42
 
43
  @app.post("/ask/")
44
  async def ask_question(query: str = Form(...)):
45
  answer = rag.ask(query)
46
  return {"question": query, "answer": answer}
47
- def main():
48
- print("Hello from rag-demo!")
49
-
50
 
51
  if __name__ == "__main__":
52
- main()
 
 
 
1
+ # app/main.py
2
  from dotenv import load_dotenv
3
+ load_dotenv() # load .env when running locally (safe: don't commit .env)
4
 
5
  from fastapi import FastAPI, UploadFile, Form, File
6
  from fastapi.middleware.cors import CORSMiddleware
7
  import fitz
8
  import os
9
+
10
+ # relative import from same package
11
  from rag_app import RAGApp
12
 
13
  app = FastAPI(title="Personal Assistant")
14
+ # Initialize after dotenv load so keys are available
15
  rag = RAGApp()
16
 
17
  app.add_middleware(
 
22
  allow_headers=["*"],
23
  )
24
 
25
+ # Keep data path inside repo (relative to project root while container runs /code)
26
+ ROOT_DIR = os.path.abspath(os.getcwd()) # when container runs, CWD will be /code
27
+ UPLOAD_DIR = os.path.join(ROOT_DIR, "data", "notes")
28
  os.makedirs(UPLOAD_DIR, exist_ok=True)
29
 
30
  def extract_text_from_pdf(pdf_path):
 
33
  for page in doc:
34
  text += page.get_text()
35
  return text
 
36
 
37
  @app.post("/upload_pdf/")
38
  async def upload_pdf(file: UploadFile = File(...)):
39
+ # sanitize filename if needed
40
+ filename = os.path.basename(file.filename)
41
+ path = os.path.join(UPLOAD_DIR, filename)
42
  with open(path, "wb") as f:
43
  f.write(await file.read())
44
  text = extract_text_from_pdf(path)
45
  chunks = rag.add_notes(text)
46
+ return {"status": "success", "message": f"{chunks} chunks added from {filename}"}
 
47
 
48
  @app.post("/ask/")
49
  async def ask_question(query: str = Form(...)):
50
  answer = rag.ask(query)
51
  return {"question": query, "answer": answer}
 
 
 
52
 
53
  if __name__ == "__main__":
54
+ import uvicorn
55
+ uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
56
+