Spaces:
Sleeping
Sleeping
phonefern
commited on
Commit
·
e04aa8c
1
Parent(s):
304b692
4/10
Browse files- Dockerfile +17 -11
- app.py +4 -12
- static/style.css +45 -0
Dockerfile
CHANGED
|
@@ -1,21 +1,27 @@
|
|
| 1 |
-
#
|
| 2 |
-
# you will also find guides on how best to write your Dockerfile
|
| 3 |
-
|
| 4 |
FROM python:3.9
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
RUN useradd -m -u 1000 user
|
| 9 |
-
WORKDIR /app
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
USER user
|
| 17 |
-
|
| 18 |
ENV HOME=/home/user \
|
| 19 |
PATH=/home/user/.local/bin:$PATH
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use the official Python 3.9 image
|
|
|
|
|
|
|
| 2 |
FROM python:3.9
|
| 3 |
|
| 4 |
+
# Set the working directory to /code
|
| 5 |
+
WORKDIR /code
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Copy the current directory contents into the container at /code
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
|
| 10 |
+
# Install requirements.txt
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 12 |
|
| 13 |
+
# Set up a new user named "user" with user ID 1000
|
| 14 |
+
RUN useradd -m -u 1000 user
|
| 15 |
+
# Switch to the "user" user
|
| 16 |
USER user
|
| 17 |
+
# Set home to the user's home directory
|
| 18 |
ENV HOME=/home/user \
|
| 19 |
PATH=/home/user/.local/bin:$PATH
|
| 20 |
|
| 21 |
+
# Set the working directory to the user's home directory
|
| 22 |
+
WORKDIR $HOME/app
|
| 23 |
+
|
| 24 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 25 |
+
COPY --chown=user . $HOME/app
|
| 26 |
+
|
| 27 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,28 +1,20 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
|
| 3 |
-
app = FastAPI()
|
| 4 |
-
|
| 5 |
-
@app.get("/")
|
| 6 |
-
def greet_json():
|
| 7 |
-
return {"Hello": "World!"}
|
| 8 |
-
|
| 9 |
-
from fastapi.responses import FileResponse
|
| 10 |
from fastapi.staticfiles import StaticFiles
|
| 11 |
-
from
|
| 12 |
|
|
|
|
| 13 |
|
|
|
|
| 14 |
|
| 15 |
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 16 |
|
| 17 |
-
|
| 18 |
@app.get("/infer_t5")
|
| 19 |
def t5(input):
|
| 20 |
output = pipe_flan(input)
|
| 21 |
return {"output": output[0]["generated_text"]}
|
| 22 |
|
| 23 |
-
|
| 24 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 25 |
|
| 26 |
@app.get("/")
|
| 27 |
def index() -> FileResponse:
|
| 28 |
-
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
|
|
|
| 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")
|
static/style.css
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
body {
|
| 2 |
+
--text: hsl(0 0% 15%);
|
| 3 |
+
padding: 2.5rem;
|
| 4 |
+
font-family: sans-serif;
|
| 5 |
+
color: var(--text);
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
body.dark-theme {
|
| 9 |
+
--text: hsl(0 0% 90%);
|
| 10 |
+
background-color: hsl(223 39% 7%);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
main {
|
| 14 |
+
max-width: 80rem;
|
| 15 |
+
text-align: center;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
section {
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-direction: column;
|
| 21 |
+
align-items: center;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
a {
|
| 25 |
+
color: var(--text);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
form {
|
| 29 |
+
width: 30rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
input {
|
| 34 |
+
width: 100%;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
button {
|
| 38 |
+
cursor: pointer;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.text-gen-output {
|
| 42 |
+
min-height: 1.2rem;
|
| 43 |
+
margin: 1rem;
|
| 44 |
+
border: 0.5px solid grey;
|
| 45 |
+
}
|