Spaces:
Sleeping
Sleeping
Witold Wydmański
commited on
Commit
•
4c6688c
1
Parent(s):
242f3e4
feat: add 3d molecule structure
Browse files
app.py
CHANGED
@@ -51,9 +51,61 @@ def suggest(option):
|
|
51 |
suggestion = ""
|
52 |
return suggestion
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
sample_code = """
|
55 |
from gradio_client import Client
|
56 |
-
import json
|
57 |
|
58 |
client = Client("https://wwydmanski-esmfold.hf.space/")
|
59 |
|
@@ -93,12 +145,17 @@ with gr.Blocks() as demo:
|
|
93 |
gr.Markdown("## Sample code")
|
94 |
gr.Code(sample_code, label="Sample usage", language="python", interactive=False)
|
95 |
|
|
|
|
|
|
|
96 |
with gr.Row():
|
97 |
with gr.Column():
|
98 |
-
gr.Markdown("## Output")
|
99 |
out = gr.Code(label="Output", interactive=False)
|
|
|
|
|
100 |
|
101 |
name.change(fn=suggest, inputs=name, outputs=inp)
|
102 |
btn.click(fold_prot_locally, inputs=[inp], outputs=[out])
|
|
|
103 |
|
104 |
demo.launch()
|
|
|
51 |
suggestion = ""
|
52 |
return suggestion
|
53 |
|
54 |
+
|
55 |
+
def molecule(mol):
|
56 |
+
print(mol)
|
57 |
+
x = (
|
58 |
+
"""<!DOCTYPE html>
|
59 |
+
<html>
|
60 |
+
<head>
|
61 |
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
62 |
+
<style>
|
63 |
+
body{
|
64 |
+
font-family:sans-serif
|
65 |
+
}
|
66 |
+
.mol-container {
|
67 |
+
width: 100%;
|
68 |
+
height: 600px;
|
69 |
+
position: relative;
|
70 |
+
}
|
71 |
+
.mol-container select{
|
72 |
+
background-image:None;
|
73 |
+
}
|
74 |
+
</style>
|
75 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
76 |
+
<script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
|
77 |
+
</head>
|
78 |
+
<body>
|
79 |
+
<div id="container" class="mol-container"></div>
|
80 |
+
|
81 |
+
<script>
|
82 |
+
let pdb = `"""
|
83 |
+
+ mol
|
84 |
+
+ """`
|
85 |
+
|
86 |
+
$(document).ready(function () {
|
87 |
+
let element = $("#container");
|
88 |
+
let config = { backgroundColor: "white" };
|
89 |
+
let viewer = $3Dmol.createViewer(element, config);
|
90 |
+
viewer.addModel(pdb, "pdb");
|
91 |
+
viewer.getModel(0).setStyle({}, { cartoon: { colorscheme:"whiteCarbon" } });
|
92 |
+
viewer.zoomTo();
|
93 |
+
viewer.render();
|
94 |
+
viewer.zoom(0.8, 2000);
|
95 |
+
})
|
96 |
+
</script>
|
97 |
+
</body></html>"""
|
98 |
+
)
|
99 |
+
|
100 |
+
return f"""<iframe style="width: 100%; height: 600px" name="result" allow="midi; geolocation; microphone; camera;
|
101 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
102 |
+
allow-scripts allow-same-origin allow-popups
|
103 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
104 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
105 |
+
|
106 |
+
|
107 |
sample_code = """
|
108 |
from gradio_client import Client
|
|
|
109 |
|
110 |
client = Client("https://wwydmanski-esmfold.hf.space/")
|
111 |
|
|
|
145 |
gr.Markdown("## Sample code")
|
146 |
gr.Code(sample_code, label="Sample usage", language="python", interactive=False)
|
147 |
|
148 |
+
with gr.Row():
|
149 |
+
gr.Markdown("## Output")
|
150 |
+
|
151 |
with gr.Row():
|
152 |
with gr.Column():
|
|
|
153 |
out = gr.Code(label="Output", interactive=False)
|
154 |
+
with gr.Column():
|
155 |
+
out_mol = gr.HTML(label="3D Structure")
|
156 |
|
157 |
name.change(fn=suggest, inputs=name, outputs=inp)
|
158 |
btn.click(fold_prot_locally, inputs=[inp], outputs=[out])
|
159 |
+
out.change(fn=molecule, inputs=[out], outputs=[out_mol])
|
160 |
|
161 |
demo.launch()
|