Piyush Bhoyar commited on
Commit
2ff1055
·
1 Parent(s): dd4330e

Server init

Browse files
Files changed (6) hide show
  1. .dockerignore +33 -0
  2. .gitignore +56 -0
  3. Dockerfile +15 -0
  4. lab.db +0 -0
  5. main.py +119 -0
  6. requirements.txt +4 -0
.dockerignore ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Git
2
+ .git
3
+ .gitignore
4
+
5
+ # Python Cache
6
+ __pycache__
7
+ *.pyc
8
+ *.pyo
9
+ *.pyd
10
+
11
+ # Local Virtual Environments (Crucial to ignore)
12
+ venv
13
+ env
14
+ .env
15
+ .venv
16
+
17
+ # Local Model Folders (Docker will download a fresh copy on Linux)
18
+ dnabert_local
19
+ *.bin
20
+ *.safetensors
21
+
22
+ # Mac System Files
23
+ .DS_Store
24
+
25
+ # Frontend Artifacts (If you have them in the same folder)
26
+ node_modules
27
+ .next
28
+ build
29
+ dist
30
+
31
+ # Docker
32
+ Dockerfile
33
+ .dockerignore
.gitignore ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --- Python ---
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ env/
8
+ venv/
9
+ .venv/
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # --- FastAPI / Environment ---
27
+ .env
28
+ .env.local
29
+
30
+ # --- Node.js / Next.js ---
31
+ node_modules/
32
+ /.next/
33
+ /out/
34
+ .next
35
+ npm-debug.log*
36
+ yarn-debug.log*
37
+ yarn-error.log*
38
+ .pnpm-debug.log*
39
+
40
+ # --- Project Specific (IMPORTANT) ---
41
+ # Don't push the massive AI model to GitHub
42
+ dnabert_local/
43
+ *.bin
44
+ *.safetensors
45
+ *.pth
46
+ *.pt
47
+
48
+ # --- Mac OS ---
49
+ .DS_Store
50
+ .AppleDouble
51
+ .LSOverride
52
+
53
+ # --- IDEs ---
54
+ .vscode/
55
+ .idea/
56
+ *.swp
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY . .
10
+
11
+ RUN mkdir -p temp_uploads
12
+
13
+ EXPOSE 8000
14
+
15
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
lab.db ADDED
Binary file (16.4 kB). View file
 
main.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ from enum import Enum
4
+ from typing import List, Optional
5
+ from datetime import datetime
6
+
7
+ from fastapi import FastAPI, Depends, HTTPException, UploadFile, File, Form
8
+ from fastapi.responses import FileResponse
9
+ from pydantic import BaseModel
10
+ from sqlalchemy import create_engine, Column, Integer, String, DateTime
11
+ from sqlalchemy.ext.declarative import declarative_base
12
+ from sqlalchemy.orm import sessionmaker, Session
13
+
14
+ SQLALCHEMY_DATABASE_URL = "sqlite:///./lab.db"
15
+
16
+ engine = create_engine(
17
+ SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
18
+ )
19
+ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
20
+
21
+ Base = declarative_base()
22
+
23
+ class RequestStatus(str, Enum):
24
+ PENDING = "pending"
25
+ FILE_UPLOADED = "file uploaded"
26
+ DONE = "done"
27
+
28
+ class LabRequest(Base):
29
+ __tablename__ = "requests"
30
+
31
+ id = Column(Integer, primary_key=True, index=True)
32
+ name = Column(String, index=True)
33
+ details = Column(String)
34
+ status = Column(String, default=RequestStatus.PENDING)
35
+ fastq_file_path = Column(String, nullable=True)
36
+ report_path = Column(String, nullable=True)
37
+ created_at = Column(DateTime, default=datetime.utcnow)
38
+
39
+ Base.metadata.create_all(bind=engine)
40
+
41
+ class RequestCreate(BaseModel):
42
+ name: str
43
+ details: str
44
+
45
+ class RequestResponse(BaseModel):
46
+ id: int
47
+ name: str
48
+ details: str
49
+ status: str
50
+ fastq_file_path: Optional[str] = None
51
+ report_path: Optional[str] = None
52
+ created_at: datetime
53
+
54
+ class Config:
55
+ from_attributes = True
56
+
57
+ app = FastAPI()
58
+
59
+ UPLOAD_DIR = "temp_uploads"
60
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
61
+
62
+ def get_db():
63
+ db = SessionLocal()
64
+ try:
65
+ yield db
66
+ finally:
67
+ db.close()
68
+
69
+ @app.post("/request", response_model=RequestResponse)
70
+ def create_request(request: RequestCreate, db: Session = Depends(get_db)):
71
+ db_request = LabRequest(
72
+ name=request.name,
73
+ details=request.details,
74
+ status=RequestStatus.PENDING
75
+ )
76
+ db.add(db_request)
77
+ db.commit()
78
+ db.refresh(db_request)
79
+ return db_request
80
+
81
+ @app.get("/get-request", response_model=List[RequestResponse])
82
+ def get_requests(db: Session = Depends(get_db)):
83
+ return db.query(LabRequest).all()
84
+
85
+ @app.put("/modify-request/{request_id}", response_model=RequestResponse)
86
+ async def modify_request(
87
+ request_id: int,
88
+ fastq_file: Optional[UploadFile] = File(None),
89
+ report_file: Optional[UploadFile] = File(None),
90
+ db: Session = Depends(get_db)
91
+ ):
92
+ db_request = db.query(LabRequest).filter(LabRequest.id == request_id).first()
93
+ if not db_request:
94
+ raise HTTPException(status_code=404, detail="Request not found")
95
+
96
+ if fastq_file:
97
+ file_location = f"{UPLOAD_DIR}/{request_id}_fastq_{fastq_file.filename}"
98
+ with open(file_location, "wb+") as file_object:
99
+ shutil.copyfileobj(fastq_file.file, file_object)
100
+ db_request.fastq_file_path = file_location
101
+ db_request.status = RequestStatus.FILE_UPLOADED
102
+
103
+ if report_file:
104
+ report_location = f"{UPLOAD_DIR}/{request_id}_report_{report_file.filename}"
105
+ with open(report_location, "wb+") as file_object:
106
+ shutil.copyfileobj(report_file.file, file_object)
107
+ db_request.report_path = report_location
108
+ db_request.status = RequestStatus.DONE
109
+
110
+ db.commit()
111
+ db.refresh(db_request)
112
+ return db_request
113
+
114
+ @app.get("/download/{filename}")
115
+ async def download_file(filename: str):
116
+ file_path = os.path.join(UPLOAD_DIR, filename)
117
+ if os.path.exists(file_path):
118
+ return FileResponse(file_path, filename=filename)
119
+ raise HTTPException(status_code=404, detail="File not found")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ sqlalchemy
4
+ python-multipart