yqcyqc commited on
Commit
cea9b8b
·
verified ·
1 Parent(s): 10afcbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -7,6 +7,7 @@ from resnest.torch import resnest50
7
  from rembg import remove
8
  from PIL import Image
9
  import io
 
10
 
11
  # 加载类别名称
12
  with open('class_names.pkl', 'rb') as f:
@@ -77,6 +78,19 @@ def predict_image(img, remove_bg=False):
77
  # 记录结果
78
  best_class = class_names[top3_indices[0]]
79
  best_conf = top3_probs[0].item() * 100
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  return processed_img, best_class, f"{best_conf:.2f}%", results
82
 
 
7
  from rembg import remove
8
  from PIL import Image
9
  import io
10
+ import requests
11
 
12
  # 加载类别名称
13
  with open('class_names.pkl', 'rb') as f:
 
78
  # 记录结果
79
  best_class = class_names[top3_indices[0]]
80
  best_conf = top3_probs[0].item() * 100
81
+
82
+
83
+ # 新增:调用本地API保存结果
84
+ api_url = "http://10.230.23.58:8806/save_result" # 替换为你的本地IP
85
+ payload = {
86
+ "filename": "uploaded_image.jpg", # 可改为实际文件名
87
+ "class": best_class,
88
+ "confidence": f"{best_conf:.2f}%"
89
+ }
90
+ try:
91
+ requests.post(api_url, json=payload, timeout=3)
92
+ except Exception as e:
93
+ print(f"保存到数据库失败: {e}")
94
 
95
  return processed_img, best_class, f"{best_conf:.2f}%", results
96