Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ from rdkit import Chem
|
|
| 18 |
from rdkit.Chem import Draw
|
| 19 |
from rdkit.Chem import AllChem
|
| 20 |
from io import BytesIO
|
|
|
|
| 21 |
|
| 22 |
# 配置日志
|
| 23 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
@@ -110,7 +111,7 @@ def load_models():
|
|
| 110 |
import torch.serialization
|
| 111 |
|
| 112 |
# 添加安全全局变量
|
| 113 |
-
torch.serialization.add_safe_globals([getattr(np
|
| 114 |
state = torch.load(pth_path, map_location=device, weights_only=True)
|
| 115 |
logger.info("使用 weights_only=True 和安全全局变量成功加载模型")
|
| 116 |
except:
|
|
@@ -287,7 +288,14 @@ with gr.Blocks(title="CrystalGAT") as demo:
|
|
| 287 |
with gr.Tab("绘制分子"):
|
| 288 |
gr.Markdown("### 绘制分子结构")
|
| 289 |
gr.Markdown("使用下方的绘图工具绘制分子结构,然后点击预测按钮")
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
drawing_display = gr.Image(label="分子结构预览", interactive=False)
|
| 292 |
drawing_output = gr.Text(label="生成的SMILES")
|
| 293 |
submit_btn2 = gr.Button("预测", variant="primary")
|
|
@@ -331,4 +339,5 @@ if __name__ == "__main__":
|
|
| 331 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 332 |
except Exception as e:
|
| 333 |
logger.error(f"启动Gradio应用失败: {str(e)}")
|
|
|
|
| 334 |
raise
|
|
|
|
| 18 |
from rdkit.Chem import Draw
|
| 19 |
from rdkit.Chem import AllChem
|
| 20 |
from io import BytesIO
|
| 21 |
+
import traceback
|
| 22 |
|
| 23 |
# 配置日志
|
| 24 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
| 111 |
import torch.serialization
|
| 112 |
|
| 113 |
# 添加安全全局变量
|
| 114 |
+
torch.serialization.add_safe_globals([getattr(np, '_core', np).multiarray.scalar])
|
| 115 |
state = torch.load(pth_path, map_location=device, weights_only=True)
|
| 116 |
logger.info("使用 weights_only=True 和安全全局变量成功加载模型")
|
| 117 |
except:
|
|
|
|
| 288 |
with gr.Tab("绘制分子"):
|
| 289 |
gr.Markdown("### 绘制分子结构")
|
| 290 |
gr.Markdown("使用下方的绘图工具绘制分子结构,然后点击预测按钮")
|
| 291 |
+
|
| 292 |
+
# 使用兼容的绘图组件
|
| 293 |
+
drawing_input = gr.Sketchpad(
|
| 294 |
+
label="绘制分子结构",
|
| 295 |
+
type="mol",
|
| 296 |
+
height=300,
|
| 297 |
+
# 移除不支持的参数
|
| 298 |
+
)
|
| 299 |
drawing_display = gr.Image(label="分子结构预览", interactive=False)
|
| 300 |
drawing_output = gr.Text(label="生成的SMILES")
|
| 301 |
submit_btn2 = gr.Button("预测", variant="primary")
|
|
|
|
| 339 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 340 |
except Exception as e:
|
| 341 |
logger.error(f"启动Gradio应用失败: {str(e)}")
|
| 342 |
+
logger.error(traceback.format_exc())
|
| 343 |
raise
|