dEN5 commited on
Commit
b6da3ae
·
1 Parent(s): 264274f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -7
main.py CHANGED
@@ -1,17 +1,16 @@
1
  from fastapi import FastAPI, File, UploadFile, HTTPException
2
- from fastapi.responses import HTMLResponse, JSONResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from PIL import Image
5
  import torch
6
  from torchvision import transforms
7
  from io import BytesIO
8
- from torch.nn import Module, Conv2d, Linear, BatchNorm2d
9
- import torch.nn as nn
10
- import torch.nn.functional as F
11
- import os
12
  import base64
13
  import io
14
 
 
 
 
15
  class CNN(nn.Module):
16
  def __init__(self, in_channels, out_channels):
17
  super(CNN, self).__init__()
@@ -65,7 +64,6 @@ html_form = """
65
  processData: false,
66
  success: function(response) {
67
  $("#prediction").text("Prediction: " + response.prediction);
68
-
69
  // Visualize the uploaded image
70
  var imageUrl = "data:image/jpeg;base64," + response.image_base64;
71
  $("#uploaded-image").html('<img src="' + imageUrl + '" alt="Uploaded Image" style="max-width: 400px; max-height: 400px;">');
@@ -97,7 +95,6 @@ html_form = """
97
  async def home():
98
  return HTMLResponse(content=html_form, status_code=200)
99
 
100
-
101
  def image_to_base64(image):
102
  # Convert the Image object to bytes
103
  img_byte_array = io.BytesIO()
 
1
  from fastapi import FastAPI, File, UploadFile, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from PIL import Image
5
  import torch
6
  from torchvision import transforms
7
  from io import BytesIO
 
 
 
 
8
  import base64
9
  import io
10
 
11
+ import torch.nn as nn
12
+ import torch.nn.functional as F
13
+
14
  class CNN(nn.Module):
15
  def __init__(self, in_channels, out_channels):
16
  super(CNN, self).__init__()
 
64
  processData: false,
65
  success: function(response) {
66
  $("#prediction").text("Prediction: " + response.prediction);
 
67
  // Visualize the uploaded image
68
  var imageUrl = "data:image/jpeg;base64," + response.image_base64;
69
  $("#uploaded-image").html('<img src="' + imageUrl + '" alt="Uploaded Image" style="max-width: 400px; max-height: 400px;">');
 
95
  async def home():
96
  return HTMLResponse(content=html_form, status_code=200)
97
 
 
98
  def image_to_base64(image):
99
  # Convert the Image object to bytes
100
  img_byte_array = io.BytesIO()