carlfeynman commited on
Commit
310a233
·
1 Parent(s): c772c06
Files changed (2) hide show
  1. server.py +12 -0
  2. static/index.html +6 -2
server.py CHANGED
@@ -8,6 +8,7 @@ import torch
8
  from pathlib import Path
9
  import datetime
10
  import numpy as np
 
11
 
12
  app = FastAPI()
13
 
@@ -44,3 +45,14 @@ async def predict(image: UploadFile):
44
  prediction = []
45
  return {"prediction": prediction}
46
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  from pathlib import Path
9
  import datetime
10
  import numpy as np
11
+ from pydantic import BaseModel
12
 
13
  app = FastAPI()
14
 
 
45
  prediction = []
46
  return {"prediction": prediction}
47
 
48
+ class Item(BaseModel):
49
+ name: str
50
+
51
+ @app.post("/home")
52
+ async def home(item: Item):
53
+ return {
54
+ 'prediction': [{
55
+ 'name': item['name']
56
+ }]
57
+ }
58
+
static/index.html CHANGED
@@ -160,9 +160,13 @@
160
  var imageData = canvas.toDataURL("image/png");
161
  var formData = new FormData();
162
  formData.append("image", dataURLtoBlob(imageData), "image.png");
163
- fetch('/predict', {
 
164
  method: 'POST',
165
- body: formData,
 
 
 
166
  })
167
  .then(response => response.json())
168
  .then(data => {
 
160
  var imageData = canvas.toDataURL("image/png");
161
  var formData = new FormData();
162
  formData.append("image", dataURLtoBlob(imageData), "image.png");
163
+ // fetch('/predict', {
164
+ fetch('/home', {
165
  method: 'POST',
166
+ // body: formData,
167
+ body: {
168
+ 'name': 'arun'
169
+ },
170
  })
171
  .then(response => response.json())
172
  .then(data => {