Sebastian Kułaga commited on
Commit
deb9cdb
1 Parent(s): 33b3bae
Files changed (4) hide show
  1. app.py +7 -2
  2. static/index.html +36 -0
  3. static/script.js +21 -0
  4. static/style.css +45 -0
app.py CHANGED
@@ -1,4 +1,6 @@
1
  from fastapi import FastAPI
 
 
2
 
3
  from routers.distilbert import prediction
4
 
@@ -6,8 +8,11 @@ from routers.distilbert import prediction
6
  app = FastAPI()
7
 
8
  app.include_router(prediction)
 
9
 
10
  @app.get("/")
11
- def greet_json():
12
- return {"detail": "AI Challenge FastAPI"}
 
 
13
 
 
1
  from fastapi import FastAPI
2
+ from fastapi.staticfiles import StaticFiles
3
+ from fastapi.responses import FileResponse
4
 
5
  from routers.distilbert import prediction
6
 
 
8
  app = FastAPI()
9
 
10
  app.include_router(prediction)
11
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
12
 
13
  @app.get("/")
14
+ def index() -> FileResponse:
15
+ return FileResponse(path="/static/index.html", media_type="text/html")
16
+ # def greet_json():
17
+ # return {"detail": "AI Challenge FastAPI"}
18
 
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="text-class">
13
+ <h1>AI Challenge Query Classification using DistilBERT</h1>
14
+ <p>
15
+ Model:
16
+ <a
17
+ href="https://huggingface.co/SebaK13/DistilBERT-finetuned-customer-queries-balanced"
18
+ rel="noreferrer"
19
+ target="_blank"
20
+ >DistilBERT</a
21
+ >
22
+ </p>
23
+ <form class="text-class-form">
24
+ <label for="text-class-input">User Query</label>
25
+ <input
26
+ id="text-class-input"
27
+ type="text"
28
+ value="Are pets allowed on flights?"
29
+ />
30
+ <button id="text-class-submit">Submit</button>
31
+ <p class="text-class-output"></p>
32
+ </form>
33
+ </section>
34
+ </main>
35
+ </body>
36
+ </html>
static/script.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const textClassForm = document.querySelector('.text-class-form');
2
+
3
+ const classifyText = async (text) => {
4
+ const inferResponse = await fetch(`predict/predict?query=${text}`);
5
+ const inferJson = await inferResponse.json();
6
+ console.log(inferJson.label)
7
+ return inferJson.label;
8
+ };
9
+
10
+ textClassForm.addEventListener('submit', async (event) => {
11
+ event.preventDefault();
12
+
13
+ const textClassInput = document.getElementById('text-class-input');
14
+ const textClassParagraph = document.querySelector('.text-class-output');
15
+
16
+ try {
17
+ textClassParagraph.textContent = await classifyText(textClassInput.value);
18
+ } catch (err) {
19
+ console.error(err);
20
+ }
21
+ });
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
+ }