Bennie12 commited on
Commit
a84bee6
Β·
verified Β·
1 Parent(s): ba8d073

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -3,8 +3,7 @@ from bert_explainer import analyze_text, analyze_image
3
  from fastapi import FastAPI, UploadFile, File, Form
4
  from fastapi.middleware.cors import CORSMiddleware
5
  import uvicorn
6
- import tempfile
7
- import os
8
 
9
 
10
  # βœ… εˆε§‹εŒ– FastAPI
@@ -54,8 +53,10 @@ def predict_text_api(payload: dict):
54
  @api.post("/run/predict_image")
55
  async def predict_image_api(file: UploadFile = File(...), explain_mode: str = Form(...)):
56
  try:
57
- img = await file.read()
58
- result = analyze_image(img,explain_mode=explain_mode)
 
 
59
 
60
  return {
61
  "data": [
 
3
  from fastapi import FastAPI, UploadFile, File, Form
4
  from fastapi.middleware.cors import CORSMiddleware
5
  import uvicorn
6
+
 
7
 
8
 
9
  # βœ… εˆε§‹εŒ– FastAPI
 
53
  @api.post("/run/predict_image")
54
  async def predict_image_api(file: UploadFile = File(...), explain_mode: str = Form(...)):
55
  try:
56
+ img_bytes = await file.read()
57
+ if not img_bytes:
58
+ raise ValueError("ζœͺζ”Άεˆ°εœ–η‰‡θ³‡ζ–™")
59
+ result = analyze_image(img_bytes, explain_mode = explain_mode)
60
 
61
  return {
62
  "data": [