Spaces:
Sleeping
Sleeping
Commit
·
9ec2d3e
1
Parent(s):
48215dc
initial commit
Browse files- Dockerfile +21 -0
- main.py +29 -0
- requirements.txt +2 -0
Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use the official Python image from Docker Hub
|
2 |
+
FROM python:3.9
|
3 |
+
|
4 |
+
|
5 |
+
RUN useradd -m -u 1000 user
|
6 |
+
USER user
|
7 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
8 |
+
|
9 |
+
WORKDIR /app
|
10 |
+
|
11 |
+
RUN mkdir -p /app/uploads && chown user:user /app/uploads
|
12 |
+
|
13 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
14 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
15 |
+
|
16 |
+
COPY --chown=user:user . /app
|
17 |
+
# Create a user with UID 1000
|
18 |
+
|
19 |
+
|
20 |
+
# Command to run the application
|
21 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
# HTML form for file upload
|
7 |
+
html_content = """
|
8 |
+
<!DOCTYPE html>
|
9 |
+
<html>
|
10 |
+
<head>
|
11 |
+
<title>File Upload</title>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<h2>Upload a File</h2>
|
15 |
+
<form action="/uploadfile/" method="post" enctype="multipart/form-data">
|
16 |
+
<input name="file" type="file">
|
17 |
+
<input type="submit">
|
18 |
+
</form>
|
19 |
+
</body>
|
20 |
+
</html>
|
21 |
+
"""
|
22 |
+
|
23 |
+
@app.get("/", response_class=HTMLResponse)
|
24 |
+
async def read_root():
|
25 |
+
return html_content
|
26 |
+
|
27 |
+
@app.post("/uploadfile/")
|
28 |
+
async def upload_file(file: UploadFile = File(...)):
|
29 |
+
return {"filename": file.filename}
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn[standard]
|