Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile.csv +29 -0
- main.py +20 -0
Dockerfile.csv
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use the official Python 3.9 image
|
2 |
+
# FROM python:3.9
|
3 |
+
FROM python:3.12 # New Python
|
4 |
+
|
5 |
+
# Set the working directory to /code
|
6 |
+
WORKDIR /code
|
7 |
+
|
8 |
+
# Copy the current directory contents into the container at /code
|
9 |
+
COPY ./requirements.txt /code/requirements.txt
|
10 |
+
|
11 |
+
# Install requirements.txt
|
12 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
13 |
+
|
14 |
+
# Set up a new user named "user" with user ID 1000
|
15 |
+
RUN useradd -m -u 1000 user
|
16 |
+
# Switch to the "user" user
|
17 |
+
USER user
|
18 |
+
# Set home to the user's home directory
|
19 |
+
ENV HOME=/home/user \
|
20 |
+
PATH=/home/user/.local/bin:$PATH
|
21 |
+
|
22 |
+
# Set the working directory to the user's home directory
|
23 |
+
WORKDIR $HOME/app
|
24 |
+
|
25 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
26 |
+
COPY --chown=user . $HOME/app
|
27 |
+
|
28 |
+
# Uvicorn: https://www.uvicorn.org/settings/ use main:app to run main.py
|
29 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.staticfiles import StaticFiles
|
3 |
+
from fastapi.responses import FileResponse
|
4 |
+
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
10 |
+
|
11 |
+
@app.get("/infer_t5")
|
12 |
+
def t5(input):
|
13 |
+
output = pipe_flan(input)
|
14 |
+
return {"output": output[0]["generated_text"]}
|
15 |
+
|
16 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
17 |
+
|
18 |
+
@app.get("/")
|
19 |
+
def index() -> FileResponse:
|
20 |
+
return FileResponse(path="/app/static/index.html", media_type="text/html")
|