Skip to content

Commit

Permalink
fastapi api server added
Browse files Browse the repository at this point in the history
  • Loading branch information
arun477 committed Sep 14, 2023
1 parent b85505a commit bfc39e7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
Empty file added __init__.py
Empty file.
21 changes: 17 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ <h3 style="text-align:center;">Draw and Predict Handwritten Digits</h3>
<button id="capture-button">Predict</button>
<button id="clear-button">Clear</button>
</div>
<div id="prediction-result"></div>
</div>
<script>
var canvas = document.getElementById('whiteboard');
Expand Down Expand Up @@ -103,13 +104,25 @@ <h3 style="text-align:center;">Draw and Predict Handwritten Digits</h3>
context.clearRect(0, 0, canvas.width, canvas.height);
});

var predictionResult = document.getElementById('prediction-result');
var captureButton = document.getElementById('capture-button');
captureButton.addEventListener('click', function () {
// Convert the canvas content to a data URL (image)
var imageData = canvas.toDataURL("image/png");

// Send the image data to the Jupyter kernel variable
IPython.notebook.kernel.execute('image_data = "' + imageData + '"');
fetch('YOUR_API_ENDPOINT', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ image: imageData }), // Send the image data as JSON
})
.then(response => response.json())
.then(data => {
predictionResult.textContent = 'Predicted Digit: ' + data.prediction;
})
.catch(error => {
console.error('Error:', error);
predictionResult.textContent = 'Prediction failed.';
});
});
</script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fastapi==0.68.1
uvicorn==0.15.0
7 changes: 7 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import FastAPI

app = FastAPI()

@app.post("/predict")
async def predict():
return {"prediction": "Hello, World!"}
14 changes: 14 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"builds": [
{
"src": "main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "server.py"
}
]
}

0 comments on commit bfc39e7

Please sign in to comment.