Spaces:
Sleeping
Sleeping
text generator
Browse files- Dockerfile +12 -3
- app.py +9 -2
- static/index.html +24 -0
- static/sctipt.js +17 -0
- static/style.css +0 -0
Dockerfile
CHANGED
@@ -1,13 +1,22 @@
|
|
|
|
|
|
|
|
|
|
1 |
FROM python:3.9
|
2 |
|
|
|
|
|
3 |
RUN useradd -m -u 1000 user
|
4 |
-
|
5 |
WORKDIR /app
|
6 |
|
7 |
COPY --chown=user ./requirements.txt requirements.txt
|
8 |
-
|
9 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
10 |
|
11 |
COPY --chown=user . /app
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
3 |
+
# you will also find guides on how best to write your Dockerfile
|
4 |
+
|
5 |
FROM python:3.9
|
6 |
|
7 |
+
# The two following lines are requirements for the Dev Mode to be functional
|
8 |
+
# Learn more about the Dev Mode at https://huggingface.co/dev-mode-explorers
|
9 |
RUN useradd -m -u 1000 user
|
|
|
10 |
WORKDIR /app
|
11 |
|
12 |
COPY --chown=user ./requirements.txt requirements.txt
|
|
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
15 |
COPY --chown=user . /app
|
16 |
|
17 |
+
USER user
|
18 |
+
|
19 |
+
ENV HOME=/home/user \
|
20 |
+
PATH=/home/user/.local/bin:$PATH
|
21 |
+
|
22 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
-
|
3 |
-
|
4 |
|
5 |
from transformers import pipeline
|
6 |
|
@@ -13,6 +13,13 @@ def t5(input):
|
|
13 |
output = pipe_flan(input)
|
14 |
return {"output": output[0]["generated_text"]}
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# @app.get('/')
|
17 |
# def greet():
|
18 |
# return {'Hello': 'Moti'}
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from starlette.responses import FileResponse
|
3 |
+
from starlette.staticfiles import StaticFiles
|
4 |
|
5 |
from transformers import pipeline
|
6 |
|
|
|
13 |
output = pipe_flan(input)
|
14 |
return {"output": output[0]["generated_text"]}
|
15 |
|
16 |
+
|
17 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
18 |
+
|
19 |
+
@app.get("/")
|
20 |
+
def index() -> FileResponse:
|
21 |
+
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
22 |
+
|
23 |
# @app.get('/')
|
24 |
# def greet():
|
25 |
# return {'Hello': 'Moti'}
|
static/index.html
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
rel="noreferrer"
|
9 |
+
target="_blank"
|
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 |
+
id="text-gen-input"
|
17 |
+
type="text"
|
18 |
+
value="German: There are many ducks"
|
19 |
+
/>
|
20 |
+
<button id="text-gen-submit">Submit</button>
|
21 |
+
<p class="text-gen-output"></p>
|
22 |
+
</form>
|
23 |
+
</section>
|
24 |
+
</main>
|
static/sctipt.js
ADDED
@@ -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 (event) => {
|
11 |
+
event.preventDefault();
|
12 |
+
|
13 |
+
const textGenInput = document.getElementById("text-gen-input");
|
14 |
+
const textGenParagraph = document.querySelector(".text-gen-output");
|
15 |
+
|
16 |
+
textGenParagraph.textContent = await translateText(textGenInput.value);
|
17 |
+
});
|
static/style.css
ADDED
File without changes
|