carlfeynman commited on
Commit
bfc39e7
1 Parent(s): b85505a

fastapi api server added

Browse files
Files changed (5) hide show
  1. __init__.py +0 -0
  2. index.html +17 -4
  3. requirements.txt +2 -0
  4. server.py +7 -0
  5. vercel.json +14 -0
__init__.py ADDED
File without changes
index.html CHANGED
@@ -70,6 +70,7 @@
70
  <button id="capture-button">Predict</button>
71
  <button id="clear-button">Clear</button>
72
  </div>
 
73
  </div>
74
  <script>
75
  var canvas = document.getElementById('whiteboard');
@@ -103,13 +104,25 @@
103
  context.clearRect(0, 0, canvas.width, canvas.height);
104
  });
105
 
 
106
  var captureButton = document.getElementById('capture-button');
107
  captureButton.addEventListener('click', function () {
108
- // Convert the canvas content to a data URL (image)
109
  var imageData = canvas.toDataURL("image/png");
110
-
111
- // Send the image data to the Jupyter kernel variable
112
- IPython.notebook.kernel.execute('image_data = "' + imageData + '"');
 
 
 
 
 
 
 
 
 
 
 
 
113
  });
114
  </script>
115
  </body>
 
70
  <button id="capture-button">Predict</button>
71
  <button id="clear-button">Clear</button>
72
  </div>
73
+ <div id="prediction-result"></div>
74
  </div>
75
  <script>
76
  var canvas = document.getElementById('whiteboard');
 
104
  context.clearRect(0, 0, canvas.width, canvas.height);
105
  });
106
 
107
+ var predictionResult = document.getElementById('prediction-result');
108
  var captureButton = document.getElementById('capture-button');
109
  captureButton.addEventListener('click', function () {
 
110
  var imageData = canvas.toDataURL("image/png");
111
+ fetch('YOUR_API_ENDPOINT', {
112
+ method: 'POST',
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ },
116
+ body: JSON.stringify({ image: imageData }), // Send the image data as JSON
117
+ })
118
+ .then(response => response.json())
119
+ .then(data => {
120
+ predictionResult.textContent = 'Predicted Digit: ' + data.prediction;
121
+ })
122
+ .catch(error => {
123
+ console.error('Error:', error);
124
+ predictionResult.textContent = 'Prediction failed.';
125
+ });
126
  });
127
  </script>
128
  </body>
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi==0.68.1
2
+ uvicorn==0.15.0
server.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+
3
+ app = FastAPI()
4
+
5
+ @app.post("/predict")
6
+ async def predict():
7
+ return {"prediction": "Hello, World!"}
vercel.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "builds": [
3
+ {
4
+ "src": "main.py",
5
+ "use": "@vercel/python"
6
+ }
7
+ ],
8
+ "routes": [
9
+ {
10
+ "src": "/(.*)",
11
+ "dest": "server.py"
12
+ }
13
+ ]
14
+ }