Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -31,8 +31,106 @@ def predict(input_mol, style, contour_level, view_str, chains):
|
|
31 |
os.system("inkscape outline_all.svg --actions='select-all;path-simplify;export-plain-svg' --export-filename pdb_opt.svg")
|
32 |
print(os.stat("outline_all.svg").st_size / (1024 * 1024))
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
with open("pdb_opt.svg", "r") as f:
|
35 |
-
return f.read(), "pdb_opt.svg"
|
36 |
|
37 |
|
38 |
|
|
|
31 |
os.system("inkscape outline_all.svg --actions='select-all;path-simplify;export-plain-svg' --export-filename pdb_opt.svg")
|
32 |
print(os.stat("outline_all.svg").st_size / (1024 * 1024))
|
33 |
|
34 |
+
html_output = """
|
35 |
+
|
36 |
+
<button id="copySvgBtn">Copy SVG to Clipboard</button>
|
37 |
+
<button id="copyPngBtn">Copy PNG to Clipboard</button>
|
38 |
+
|
39 |
+
<!-- Buttons for Download -->
|
40 |
+
<button id="downloadSvgBtn">Download SVG</button>
|
41 |
+
<button id="downloadPngBtn">Download PNG</button>
|
42 |
+
<script>
|
43 |
+
function copySvgToClipboard() {
|
44 |
+
const svgElement = document.getElementById('svgElement');
|
45 |
+
const svgData = new XMLSerializer().serializeToString(svgElement);
|
46 |
+
const blob = new Blob([svgData], { type: 'image/svg+xml' });
|
47 |
+
const clipboardItem = [new ClipboardItem({ 'image/svg+xml': blob })];
|
48 |
+
|
49 |
+
navigator.clipboard.write(clipboardItem).then(() => {
|
50 |
+
alert("SVG copied to clipboard!");
|
51 |
+
}).catch(err => {
|
52 |
+
console.error("Could not copy SVG to clipboard: ", err);
|
53 |
+
});
|
54 |
+
}
|
55 |
+
|
56 |
+
// Function to convert SVG to PNG and copy to clipboard
|
57 |
+
function copyPngToClipboard() {
|
58 |
+
const svgElement = document.getElementById('svgElement');
|
59 |
+
const svgData = new XMLSerializer().serializeToString(svgElement);
|
60 |
+
const canvas = document.createElement('canvas');
|
61 |
+
const ctx = canvas.getContext('2d');
|
62 |
+
const img = new Image();
|
63 |
+
|
64 |
+
img.onload = function () {
|
65 |
+
canvas.width = svgElement.clientWidth;
|
66 |
+
canvas.height = svgElement.clientHeight;
|
67 |
+
ctx.drawImage(img, 0, 0);
|
68 |
+
canvas.toBlob(blob => {
|
69 |
+
const clipboardItem = [new ClipboardItem({ 'image/png': blob })];
|
70 |
+
navigator.clipboard.write(clipboardItem).then(() => {
|
71 |
+
alert("PNG copied to clipboard!");
|
72 |
+
}).catch(err => {
|
73 |
+
console.error("Could not copy PNG to clipboard: ", err);
|
74 |
+
});
|
75 |
+
}, 'image/png');
|
76 |
+
};
|
77 |
+
|
78 |
+
img.src = 'data:image/svg+xml;base64,' + btoa(svgData);
|
79 |
+
}
|
80 |
+
|
81 |
+
// Function to download SVG
|
82 |
+
function downloadSvg() {
|
83 |
+
const svgElement = document.getElementById('svgElement');
|
84 |
+
const svgData = new XMLSerializer().serializeToString(svgElement);
|
85 |
+
const blob = new Blob([svgData], { type: 'image/svg+xml' });
|
86 |
+
const url = URL.createObjectURL(blob);
|
87 |
+
|
88 |
+
const a = document.createElement('a');
|
89 |
+
a.href = url;
|
90 |
+
a.download = 'image.svg';
|
91 |
+
document.body.appendChild(a);
|
92 |
+
a.click();
|
93 |
+
document.body.removeChild(a);
|
94 |
+
URL.revokeObjectURL(url);
|
95 |
+
}
|
96 |
+
|
97 |
+
// Function to download PNG
|
98 |
+
function downloadPng() {
|
99 |
+
const svgElement = document.getElementById('svgElement');
|
100 |
+
const svgData = new XMLSerializer().serializeToString(svgElement);
|
101 |
+
const canvas = document.createElement('canvas');
|
102 |
+
const ctx = canvas.getContext('2d');
|
103 |
+
const img = new Image();
|
104 |
+
|
105 |
+
img.onload = function () {
|
106 |
+
canvas.width = svgElement.clientWidth;
|
107 |
+
canvas.height = svgElement.clientHeight;
|
108 |
+
ctx.drawImage(img, 0, 0);
|
109 |
+
canvas.toBlob(blob => {
|
110 |
+
const url = URL.createObjectURL(blob);
|
111 |
+
const a = document.createElement('a');
|
112 |
+
a.href = url;
|
113 |
+
a.download = 'image.png';
|
114 |
+
document.body.appendChild(a);
|
115 |
+
a.click();
|
116 |
+
document.body.removeChild(a);
|
117 |
+
URL.revokeObjectURL(url);
|
118 |
+
}, 'image/png');
|
119 |
+
};
|
120 |
+
|
121 |
+
img.src = 'data:image/svg+xml;base64,' + btoa(svgData);
|
122 |
+
}
|
123 |
+
|
124 |
+
// Button event listeners
|
125 |
+
document.getElementById('copySvgBtn').addEventListener('click', copySvgToClipboard);
|
126 |
+
document.getElementById('copyPngBtn').addEventListener('click', copyPngToClipboard);
|
127 |
+
document.getElementById('downloadSvgBtn').addEventListener('click', downloadSvg);
|
128 |
+
document.getElementById('downloadPngBtn').addEventListener('click', downloadPng);
|
129 |
+
</script>
|
130 |
+
"""
|
131 |
+
|
132 |
with open("pdb_opt.svg", "r") as f:
|
133 |
+
return f.read().replace("<svg", "<svg id='svgElement'")+html_output, "pdb_opt.svg"
|
134 |
|
135 |
|
136 |
|