i_vorobyev commited on
Commit
0014c63
·
1 Parent(s): f3bdc4c

add download button

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  from igfold import IgFoldRunner
3
  import os
4
  import random
 
 
5
 
6
  def read_mol(molpath):
7
  with open(molpath, "r") as fp:
@@ -16,6 +18,10 @@ def molecule(input_pdb):
16
 
17
  mol = read_mol(input_pdb)
18
 
 
 
 
 
19
  x = (
20
  """<!DOCTYPE html>
21
  <html>
@@ -44,7 +50,6 @@ def molecule(input_pdb):
44
  let pdb = `"""
45
  + mol
46
  + """`
47
-
48
  $(document).ready(function () {
49
  let element = $("#container");
50
  let config = { backgroundColor: "white" };
@@ -65,7 +70,7 @@ def molecule(input_pdb):
65
  allow-scripts allow-same-origin allow-popups
66
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
67
  allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>
68
- <p><input type="button" id="dwn-btn" value="Download dinamically generated text file"/></p>
69
  """
70
 
71
 
 
2
  from igfold import IgFoldRunner
3
  import os
4
  import random
5
+ import base64
6
+
7
 
8
  def read_mol(molpath):
9
  with open(molpath, "r") as fp:
 
18
 
19
  mol = read_mol(input_pdb)
20
 
21
+ byte_content = mol.encode('utf-8')
22
+ base64_content = base64.b64encode(byte_content).decode('utf-8')
23
+
24
+
25
  x = (
26
  """<!DOCTYPE html>
27
  <html>
 
50
  let pdb = `"""
51
  + mol
52
  + """`
 
53
  $(document).ready(function () {
54
  let element = $("#container");
55
  let config = { backgroundColor: "white" };
 
70
  allow-scripts allow-same-origin allow-popups
71
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
72
  allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>
73
+ <a href="data:application/octet-stream;base64,{base64_content}" download="example.txt">Download File</a>
74
  """
75
 
76