Spaces:
Runtime error
Runtime error
CaesarCloudSync
commited on
Commit
·
66e21cf
1
Parent(s):
90121d5
Add application file main docker
Browse files- main.py +5 -3
- static/index.html +36 -0
- static/script.js +17 -0
main.py
CHANGED
@@ -2,17 +2,19 @@ from fastapi import FastAPI
|
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
4 |
|
5 |
-
|
6 |
app = FastAPI()
|
7 |
|
8 |
-
|
9 |
|
10 |
@app.get("/")
|
11 |
def index() -> FileResponse:
|
12 |
-
return
|
13 |
|
14 |
|
|
|
15 |
|
|
|
16 |
|
17 |
@app.get("/infer_t5")
|
18 |
def t5(input):
|
|
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
4 |
|
5 |
+
|
6 |
app = FastAPI()
|
7 |
|
8 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
9 |
|
10 |
@app.get("/")
|
11 |
def index() -> FileResponse:
|
12 |
+
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
13 |
|
14 |
|
15 |
+
from transformers import pipeline
|
16 |
|
17 |
+
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
18 |
|
19 |
@app.get("/infer_t5")
|
20 |
def t5(input):
|
static/index.html
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<main>
|
2 |
+
<section id="text-gen">
|
3 |
+
<h2 class="relative group">
|
4 |
+
<a
|
5 |
+
id="text-generation-using-flan-t5"
|
6 |
+
class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"
|
7 |
+
href="#text-generation-using-flan-t5"
|
8 |
+
>
|
9 |
+
<span><IconCopyLink/></span>
|
10 |
+
</a>
|
11 |
+
<span>
|
12 |
+
Text generation using Flan T5
|
13 |
+
</span>
|
14 |
+
</h2>
|
15 |
+
|
16 |
+
<p>
|
17 |
+
Model:
|
18 |
+
<a
|
19 |
+
href="https://huggingface.co/google/flan-t5-small"
|
20 |
+
rel="noreferrer"
|
21 |
+
target="_blank"
|
22 |
+
>google/flan-t5-small
|
23 |
+
</a>
|
24 |
+
</p>
|
25 |
+
<form class="text-gen-form">
|
26 |
+
<label for="text-gen-input">Text prompt</label>
|
27 |
+
<input
|
28 |
+
id="text-gen-input"
|
29 |
+
type="text"
|
30 |
+
value="German: There are many ducks"
|
31 |
+
/>
|
32 |
+
<button id="text-gen-submit">Submit</button>
|
33 |
+
<p class="text-gen-output"></p>
|
34 |
+
</form>
|
35 |
+
</section>
|
36 |
+
</main>
|
static/script.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 |
+
});
|