Spaces:
Runtime error
Runtime error
Commit ·
9b62d45
1
Parent(s): 734f662
more
Browse files- app.py +8 -2
- static/index.html +36 -0
- static/script.js +17 -0
app.py
CHANGED
|
@@ -14,7 +14,7 @@ from cltk.languages.utils import get_lang
|
|
| 14 |
from cltk.alphabet.processes import LatinNormalizeProcess
|
| 15 |
from cltk.nlp import NLP
|
| 16 |
from cltk.text.processes import DefaultPunctuationRemovalProcess
|
| 17 |
-
from fastapi import FastAPI
|
| 18 |
from typing import Optional
|
| 19 |
import json
|
| 20 |
from transformers import AutoTokenizer
|
|
@@ -236,4 +236,10 @@ async def process(text: Optional[str] = None):
|
|
| 236 |
result = process_handler(text)
|
| 237 |
return json.dumps(result)
|
| 238 |
else:
|
| 239 |
-
return json.dumps({"error": "Missing required parameter 'text'"}), 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
from cltk.alphabet.processes import LatinNormalizeProcess
|
| 15 |
from cltk.nlp import NLP
|
| 16 |
from cltk.text.processes import DefaultPunctuationRemovalProcess
|
| 17 |
+
from fastapi import FastAPI, StaticFiles, FileResponse
|
| 18 |
from typing import Optional
|
| 19 |
import json
|
| 20 |
from transformers import AutoTokenizer
|
|
|
|
| 236 |
result = process_handler(text)
|
| 237 |
return json.dumps(result)
|
| 238 |
else:
|
| 239 |
+
return json.dumps({"error": "Missing required parameter 'text'"}), 400
|
| 240 |
+
|
| 241 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 242 |
+
|
| 243 |
+
@app.get("/")
|
| 244 |
+
def index() -> FileResponse:
|
| 245 |
+
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
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 |
+
Pre-process some text
|
| 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(`process?input=${text}`);
|
| 5 |
+
const inferJson = await inferResponse.json();
|
| 6 |
+
|
| 7 |
+
return inferJson;
|
| 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 |
+
});
|