Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from fastapi.responses import JSONResponse
|
| 5 |
|
|
@@ -76,28 +77,32 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 76 |
# Clamp score between 0 and 1
|
| 77 |
confidence_score = max(0.0, min(1.0, confidence_score))
|
| 78 |
|
| 79 |
-
|
|
|
|
| 80 |
"success": True,
|
| 81 |
"diffdock_confidence_score": round(confidence_score, 4),
|
| 82 |
"hardware_allocation": "HF_FREE_CPU_TIER",
|
| 83 |
"molecular_properties": {
|
| 84 |
"molecular_weight": round(mw, 2),
|
| 85 |
"logP": round(logp, 2),
|
| 86 |
-
"h_bond_donors": hbd,
|
| 87 |
-
"h_bond_acceptors": hba,
|
| 88 |
"tpsa": round(tpsa, 2),
|
| 89 |
-
"rotatable_bonds": rotatable_bonds,
|
| 90 |
-
"lipinski_compliant": lipinski_pass
|
| 91 |
},
|
| 92 |
"note": "RDKit-based drug-likeness scoring (lightweight alternative to DiffDock)"
|
| 93 |
}
|
|
|
|
| 94 |
|
| 95 |
except Exception as runtime_fault:
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 98 |
"error_log": str(runtime_fault)[:200],
|
| 99 |
"diffdock_confidence_score": -1.0
|
| 100 |
}
|
|
|
|
| 101 |
|
| 102 |
# 🌐 FastAPI app for custom endpoints
|
| 103 |
app = FastAPI()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import json
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.responses import JSONResponse
|
| 6 |
|
|
|
|
| 77 |
# Clamp score between 0 and 1
|
| 78 |
confidence_score = max(0.0, min(1.0, confidence_score))
|
| 79 |
|
| 80 |
+
# Return as JSON string to avoid Gradio JsonData serialization issues
|
| 81 |
+
result = {
|
| 82 |
"success": True,
|
| 83 |
"diffdock_confidence_score": round(confidence_score, 4),
|
| 84 |
"hardware_allocation": "HF_FREE_CPU_TIER",
|
| 85 |
"molecular_properties": {
|
| 86 |
"molecular_weight": round(mw, 2),
|
| 87 |
"logP": round(logp, 2),
|
| 88 |
+
"h_bond_donors": int(hbd),
|
| 89 |
+
"h_bond_acceptors": int(hba),
|
| 90 |
"tpsa": round(tpsa, 2),
|
| 91 |
+
"rotatable_bonds": int(rotatable_bonds),
|
| 92 |
+
"lipinski_compliant": bool(lipinski_pass)
|
| 93 |
},
|
| 94 |
"note": "RDKit-based drug-likeness scoring (lightweight alternative to DiffDock)"
|
| 95 |
}
|
| 96 |
+
return result
|
| 97 |
|
| 98 |
except Exception as runtime_fault:
|
| 99 |
+
# Return as JSON string to avoid Gradio JsonData serialization issues
|
| 100 |
+
result = {
|
| 101 |
+
"success": False,
|
| 102 |
"error_log": str(runtime_fault)[:200],
|
| 103 |
"diffdock_confidence_score": -1.0
|
| 104 |
}
|
| 105 |
+
return result
|
| 106 |
|
| 107 |
# 🌐 FastAPI app for custom endpoints
|
| 108 |
app = FastAPI()
|