未验证 提交 820aeb2e 编写于 作者: D DanielYang 提交者: GitHub

test=develop, test=update_app (#5716)

上级 1fbf4a3a
import gradio as gr import gradio as gr
import os import os
def molecule(input_pdb): def molecule(input_pdb):
mol = read_mol(input_pdb) mol = read_mol(input_pdb)
x = ( x = ("""<!DOCTYPE html>
"""<!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
...@@ -24,14 +24,13 @@ def molecule(input_pdb): ...@@ -24,14 +24,13 @@ def molecule(input_pdb):
} }
</style> </style>
<script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script> <script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
</head> </head>
<body> <body>
<div id="container" class="mol-container"></div> <div id="container" class="mol-container"></div>
<script> <script>
let pdb = `""" let pdb = `""" + mol + """`
+ mol
+ """`
$(document).ready(function () { $(document).ready(function () {
let element = $("#container"); let element = $("#container");
...@@ -44,8 +43,7 @@ def molecule(input_pdb): ...@@ -44,8 +43,7 @@ def molecule(input_pdb):
viewer.zoom(1, 1000); /* slight zoom */ viewer.zoom(1, 1000); /* slight zoom */
}) })
</script> </script>
</body></html>""" </body></html>""")
)
return f"""<iframe style="width: 100%; height: 600px" name="result" allow="midi; geolocation; microphone; camera; return f"""<iframe style="width: 100%; height: 600px" name="result" allow="midi; geolocation; microphone; camera;
display-capture; encrypted-media;" sandbox="allow-modals allow-forms display-capture; encrypted-media;" sandbox="allow-modals allow-forms
...@@ -53,6 +51,7 @@ def molecule(input_pdb): ...@@ -53,6 +51,7 @@ def molecule(input_pdb):
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen="" allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>""" allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
def get_pdb(pdb_code="", filepath=""): def get_pdb(pdb_code="", filepath=""):
if pdb_code is None or pdb_code == "": if pdb_code is None or pdb_code == "":
try: try:
...@@ -73,23 +72,24 @@ def read_mol(molpath): ...@@ -73,23 +72,24 @@ def read_mol(molpath):
return mol return mol
def update(fastaName='', fastaContent=''):
def update(fastaName='',fastaContent=''): if (fastaName == ''):
if(fastaName==''):
return None return None
else: else:
return molecule(fastaName+"_pred.pdb") return molecule(fastaName + "_pred.pdb")
demo = gr.Blocks() demo = gr.Blocks()
with demo: with demo:
gr.Markdown("# PP-HelixFold Protein Structure Prediction Demo") gr.Markdown("# PP-HelixFold Demo")
with gr.Row(): with gr.Row():
with gr.Box(): with gr.Box():
fastaName = gr.Textbox(interactive=False,label='Fasta label') fastaName = gr.Textbox(interactive=False, label='Fasta label')
fastaContent = gr.Textbox(interactive=False,label='Fasta content') fastaContent = gr.Textbox(interactive=False, label='Fasta content')
gr.Examples([["T1026", read_mol( "T1026.fasta")],["T1037", read_mol("T1037.fasta")]], [fastaName,fastaContent]) gr.Examples([["T1026", read_mol("T1026.fasta")],
["T1037", read_mol("T1037.fasta")]],
[fastaName, fastaContent])
btn = gr.Button("Predict") btn = gr.Button("Predict")
mol = gr.HTML() mol = gr.HTML()
btn.click(fn=update, inputs=[fastaName,fastaContent], outputs=mol) btn.click(fn=update, inputs=[fastaName, fastaContent], outputs=mol)
demo.launch() demo.launch()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册