Spaces:
Runtime error
Runtime error
update
Browse files- Dockerfile +16 -2
- main.py +7 -2
- static/index.html +26 -0
- static/script.js +17 -0
Dockerfile
CHANGED
@@ -1,11 +1,25 @@
|
|
1 |
FROM python:3.9
|
2 |
|
3 |
-
WORkDIR /code
|
4 |
-
|
5 |
COPY ./requirements.txt /code/requirements.txt
|
6 |
|
7 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
|
9 |
COPY . .
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
FROM python:3.9
|
2 |
|
|
|
|
|
3 |
COPY ./requirements.txt /code/requirements.txt
|
4 |
|
5 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
6 |
|
7 |
COPY . .
|
8 |
|
9 |
+
# setup new user
|
10 |
+
RUN useradd -m -u 1000 user
|
11 |
+
|
12 |
+
WORkDIR /code
|
13 |
+
|
14 |
+
# switch to the new user
|
15 |
+
USER user
|
16 |
+
|
17 |
+
# set home to the new user's home
|
18 |
+
ENV HOME=/home/user \
|
19 |
+
PATH=/home/user/.local/bin:$PATH
|
20 |
+
|
21 |
+
WORKDIR /app
|
22 |
+
|
23 |
+
COPY --chown=user . $HOME/app
|
24 |
+
|
25 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
CHANGED
@@ -1,7 +1,12 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
|
3 |
app = FastAPI()
|
|
|
4 |
|
5 |
@app.get("/")
|
6 |
-
def
|
7 |
-
return
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
|
3 |
app = FastAPI()
|
4 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
5 |
|
6 |
@app.get("/")
|
7 |
+
def index() -> FileResponse:
|
8 |
+
return FileResponse(path="/static/index.html", media_type="text/html")
|
9 |
+
|
10 |
+
def t5(input):
|
11 |
+
output = pipe_flan(input)
|
12 |
+
return {"output": output[0]["generated_text"]}
|
static/index.html
CHANGED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<main>
|
2 |
+
<section id="text-gen">
|
3 |
+
<h2>Text generation using Flan T5</h2>
|
4 |
+
<p>
|
5 |
+
Model:
|
6 |
+
<a
|
7 |
+
href="https://huggingface.co/google/flan-t5-small"
|
8 |
+
target="_blank"
|
9 |
+
rel="noreferrer">
|
10 |
+
google/flan-t5-small
|
11 |
+
</a>
|
12 |
+
</p>
|
13 |
+
<form class="text-gen-form">
|
14 |
+
<label for="text-gen-input">Text prompt</label>
|
15 |
+
<input
|
16 |
+
type="text"
|
17 |
+
id="text-gen-input"
|
18 |
+
name="text-gen-input"
|
19 |
+
placeholder="Enter text prompt here"
|
20 |
+
required
|
21 |
+
value="German: There are many ducks"/>
|
22 |
+
<button id="text-gen-submit" type="submit">Generate</button>
|
23 |
+
<p class="text-gen-output"></p>
|
24 |
+
</form>
|
25 |
+
</section>
|
26 |
+
</main>
|
static/script.js
CHANGED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const textGenForm = document.querySelector(".text-gen-form")
|
2 |
+
|
3 |
+
const translateText = async (text) => {
|
4 |
+
const inferResponse = await fetch('infer_t5?input=${text}');
|
5 |
+
const inferJson = await inferResponse.json();
|
6 |
+
|
7 |
+
return inferJson.output;
|
8 |
+
}
|
9 |
+
|
10 |
+
textGenForm.addEventListener("submit", async (e) => {
|
11 |
+
e.preventDefault();
|
12 |
+
|
13 |
+
const textGenInput = document.getElementById("text-gen-input");
|
14 |
+
const textGenParagraph = document.getElementById("text-gen-output");
|
15 |
+
|
16 |
+
textGenParagraph.textContent = await translateText(textGenInput.value);
|
17 |
+
});
|