Update app.py
Browse files
app.py
CHANGED
|
@@ -19,14 +19,31 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
def gradio_predict(image):
|
| 20 |
try:
|
| 21 |
# 使用临时文件目录保存图片
|
| 22 |
-
with tempfile.NamedTemporaryFile(suffix=".png", dir="/temp", delete=False) as temp_file:
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
image.save(temp_path)
|
| 26 |
-
logger.info(f"图片已保存至: {temp_path}")
|
| 27 |
|
| 28 |
-
#
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
smiles = predict_smiles(temp_path)
|
| 31 |
logger.info(f"SMILES 输出: {smiles}")
|
| 32 |
|
|
|
|
| 19 |
def gradio_predict(image):
|
| 20 |
try:
|
| 21 |
# 使用临时文件目录保存图片
|
| 22 |
+
# with tempfile.NamedTemporaryFile(suffix=".png", dir="/temp", delete=False) as temp_file:
|
| 23 |
+
# temp_path = temp_file.name
|
| 24 |
+
# logger.info(f"temp_path: {temp_path}")
|
| 25 |
+
# image.save(temp_path)
|
| 26 |
+
# logger.info(f"图片已保存至: {temp_path}")
|
| 27 |
+
|
| 28 |
+
# # 调用模型的 main 函数
|
| 29 |
+
if image is None:
|
| 30 |
+
logger.error("上传的图片为空")
|
| 31 |
+
return "错误: 请上传有效的图片文件"
|
| 32 |
+
|
| 33 |
+
# 使用 /home/user/app 保存临时文件
|
| 34 |
+
with tempfile.NamedTemporaryFile(suffix=".png", dir="/home/user/app", delete=False) as temp_file:
|
| 35 |
+
temp_path = os.path.abspath(temp_file.name)
|
| 36 |
+
logger.info(f"保存图片到: {temp_path}")
|
| 37 |
image.save(temp_path)
|
|
|
|
| 38 |
|
| 39 |
+
# 验证文件存在
|
| 40 |
+
if not os.path.exists(temp_path):
|
| 41 |
+
logger.error(f"图片文件未正确保存: {temp_path}")
|
| 42 |
+
return f"错误: 图片文件未正确保存 - {temp_path}"
|
| 43 |
|
| 44 |
+
# 检查路径内容(调试 't' 问题)
|
| 45 |
+
logger.info(f"传递给 main 的路径: {temp_path}, 类型: {type(temp_path)}")
|
| 46 |
+
|
| 47 |
smiles = predict_smiles(temp_path)
|
| 48 |
logger.info(f"SMILES 输出: {smiles}")
|
| 49 |
|