Spaces:
Running
Running
Add a home page for the huggingface hub
Browse filesBreaks integration tests,
and now you cannot access the API endpoint from outside (is it good?
I guess it is)
- Dockerfile +1 -1
- README.md +3 -1
- app.py +12 -10
- static/index.html +36 -0
- static/script.js +25 -0
- static/style.css +45 -0
Dockerfile
CHANGED
@@ -9,7 +9,7 @@ ENV PATH="/venv/bin:$PATH"
|
|
9 |
COPY requirements.txt .
|
10 |
COPY test-requirements.txt .
|
11 |
RUN pip install --upgrade pip
|
12 |
-
RUN pip install -r requirements.txt
|
13 |
|
14 |
COPY src/baseline.py src/baseline.py
|
15 |
ENV TRANSFORMERS_CACHE=/coma-fixer/.cache
|
|
|
9 |
COPY requirements.txt .
|
10 |
COPY test-requirements.txt .
|
11 |
RUN pip install --upgrade pip
|
12 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
13 |
|
14 |
COPY src/baseline.py src/baseline.py
|
15 |
ENV TRANSFORMERS_CACHE=/coma-fixer/.cache
|
README.md
CHANGED
@@ -12,4 +12,6 @@ app_port: 8000
|
|
12 |
|
13 |
`docker log [id]` for logs from the container.
|
14 |
|
15 |
-
`docker build -t comma-fixer --target test .` for tests
|
|
|
|
|
|
12 |
|
13 |
`docker log [id]` for logs from the container.
|
14 |
|
15 |
+
`docker build -t comma-fixer --target test .` for tests
|
16 |
+
|
17 |
+
`git push hub` to deploy to huggingface hub, after adding a remote
|
app.py
CHANGED
@@ -1,23 +1,18 @@
|
|
1 |
import uvicorn
|
2 |
from fastapi import FastAPI, HTTPException
|
|
|
|
|
3 |
from src.baseline import BaselineCommaFixer
|
4 |
import logging
|
5 |
|
6 |
logger = logging.Logger(__name__)
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
|
9 |
-
app = FastAPI()
|
10 |
logger.info('Loading the baseline model...')
|
11 |
app.baseline_model = BaselineCommaFixer()
|
12 |
|
13 |
|
14 |
-
@app.get('/')
|
15 |
-
async def root():
|
16 |
-
return ("Welcome to the comma fixer. Send a POST request to /fix-commas or /baseline/fix-commas with a string "
|
17 |
-
"'s' in the JSON body to try "
|
18 |
-
"out the functionality.")
|
19 |
-
|
20 |
-
|
21 |
@app.post('/baseline/fix-commas/')
|
22 |
async def fix_commas_with_baseline(data: dict):
|
23 |
json_field_name = 's'
|
@@ -30,6 +25,13 @@ async def fix_commas_with_baseline(data: dict):
|
|
30 |
raise HTTPException(status_code=400, detail=msg)
|
31 |
|
32 |
|
33 |
-
|
34 |
-
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import uvicorn
|
2 |
from fastapi import FastAPI, HTTPException
|
3 |
+
from fastapi.staticfiles import StaticFiles
|
4 |
+
from fastapi.responses import FileResponse
|
5 |
from src.baseline import BaselineCommaFixer
|
6 |
import logging
|
7 |
|
8 |
logger = logging.Logger(__name__)
|
9 |
logging.basicConfig(level=logging.INFO)
|
10 |
|
11 |
+
app = FastAPI() # TODO router?
|
12 |
logger.info('Loading the baseline model...')
|
13 |
app.baseline_model = BaselineCommaFixer()
|
14 |
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
@app.post('/baseline/fix-commas/')
|
17 |
async def fix_commas_with_baseline(data: dict):
|
18 |
json_field_name = 's'
|
|
|
25 |
raise HTTPException(status_code=400, detail=msg)
|
26 |
|
27 |
|
28 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
29 |
+
|
30 |
|
31 |
+
@app.get('/')
|
32 |
+
async def index() -> FileResponse:
|
33 |
+
return FileResponse(path="static/index.html", media_type="text/html")
|
34 |
+
|
35 |
+
|
36 |
+
if __name__ == '__main__':
|
37 |
+
uvicorn.run("app:app", port=8000)
|
static/index.html
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
+
<title>Fast API 🤗 Space served with Uvicorn</title>
|
7 |
+
<link rel="stylesheet" href="style.css" />
|
8 |
+
<script type="module" src="script.js"></script>
|
9 |
+
</head>
|
10 |
+
<body>
|
11 |
+
<main>
|
12 |
+
<section id="comma-fixing">
|
13 |
+
<h2>Fixing commas using Transformers</h2>
|
14 |
+
<p>
|
15 |
+
Model:
|
16 |
+
<a
|
17 |
+
href="https://huggingface.co/oliverguhr/fullstop-punctuation-multilang-large"
|
18 |
+
rel="noreferrer"
|
19 |
+
target="_blank"
|
20 |
+
>oliverguhr/fullstop-punctuation-multilang-large
|
21 |
+
</a>
|
22 |
+
</p>
|
23 |
+
<form class="comma-fixing-form">
|
24 |
+
<label for="comma-fixing-input">Text with incorrect commas</label>
|
25 |
+
<input
|
26 |
+
id="comma-fixing-input"
|
27 |
+
type="text"
|
28 |
+
value="This is however a very bad, and terrible sentence grammatically that is."
|
29 |
+
/>
|
30 |
+
<button id="comma-fixing-submit">Submit</button>
|
31 |
+
<p class="comma-fixing-output"></p>
|
32 |
+
</form>
|
33 |
+
</section>
|
34 |
+
</main>
|
35 |
+
</body>
|
36 |
+
</html>
|
static/script.js
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const commaFixingForm = document.querySelector(".comma-fixing-form");
|
2 |
+
|
3 |
+
const fixCommas = async (text) => {
|
4 |
+
const inferResponse = await fetch(`baseline/fix-commas/`, {
|
5 |
+
method: "POST",
|
6 |
+
body: JSON.stringify({
|
7 |
+
s: text
|
8 |
+
}),
|
9 |
+
headers: {
|
10 |
+
"Content-type": "application/json; charset=UTF-8"
|
11 |
+
}
|
12 |
+
});
|
13 |
+
const inferJson = await inferResponse.json();
|
14 |
+
|
15 |
+
return inferJson.s;
|
16 |
+
};
|
17 |
+
|
18 |
+
commaFixingForm.addEventListener("submit", async (event) => {
|
19 |
+
event.preventDefault();
|
20 |
+
|
21 |
+
const commaFixingInput = document.getElementById("comma-fixing-input");
|
22 |
+
const commaFixingParagraph = document.querySelector(".comma-fixing-output");
|
23 |
+
|
24 |
+
commaFixingParagraph.textContent = await fixCommas(commaFixingInput.value);
|
25 |
+
});
|
static/style.css
ADDED
@@ -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 |
+
}
|