Nausad commited on
Commit
eb0cb39
·
verified ·
1 Parent(s): e14fed6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -97,41 +97,34 @@ def index():
97
 
98
  @app.route("/predict", methods=["POST"])
99
  def predict():
 
100
  if "file" not in request.files:
101
  return jsonify({"error": "No file uploaded"}), 400
102
 
103
  file = request.files["file"]
104
 
105
- print("Filename:", file.filename)
106
- print("Content-Type:", file.content_type)
107
-
108
- image_bytes = file.read()
109
-
110
- print("Bytes length:", len(image_bytes))
111
- print("First 50 bytes:", image_bytes[:50])
112
 
113
- try:
114
- data = file.read()
 
115
 
116
- print("Filename:", file.filename)
117
- print("Content-Type:", file.content_type)
118
- print("Bytes length:", len(data))
119
 
120
- img = Image.open(io.BytesIO(data))
121
- print("Format:", img.format)
122
- print("Size:", img.size)
123
 
124
- img = img.convert("RGB")
125
 
126
- tensor = transform(img).unsqueeze(0).to(device)
 
127
 
128
- t0 = time.time()
129
- with torch.no_grad():
130
- logits = model(tensor)
131
- probs = F.softmax(logits, dim=1).squeeze(0)
132
 
133
  except Exception as e:
134
- print("ERROR:", e)
135
  return jsonify({"error": str(e)}), 500
136
 
137
  @app.route("/model-info")
 
97
 
98
  @app.route("/predict", methods=["POST"])
99
  def predict():
100
+
101
  if "file" not in request.files:
102
  return jsonify({"error": "No file uploaded"}), 400
103
 
104
  file = request.files["file"]
105
 
106
+ try:
107
+ data = file.read()
 
 
 
 
 
108
 
109
+ print("Filename:", file.filename)
110
+ print("Content-Type:", file.content_type)
111
+ print("Bytes length:", len(data))
112
 
113
+ img = Image.open(io.BytesIO(data))
114
+ print("Format:", img.format)
115
+ print("Size:", img.size)
116
 
117
+ img = img.convert("RGB")
 
 
118
 
119
+ tensor = transform(img).unsqueeze(0).to(device)
120
 
121
+ with torch.no_grad():
122
+ logits = model(tensor)
123
 
124
+ return jsonify({"success": True})
 
 
 
125
 
126
  except Exception as e:
127
+ print("ERROR:", repr(e))
128
  return jsonify({"error": str(e)}), 500
129
 
130
  @app.route("/model-info")