ObviousSatire commited on
Commit
c049bcc
Β·
1 Parent(s): bcb28f0

Fix file upload handling in app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -14,8 +14,24 @@ zero = torch.Tensor([0]).cuda() if torch.cuda.is_available() else torch.Tensor([
14
  print(f"Device: {zero.device}")
15
 
16
  @spaces.GPU
17
- def run_gaia(protein_content, ligand_content, use_cphmd=False, use_qmmm=False):
18
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  with tempfile.NamedTemporaryFile(suffix=".pdb", delete=False, mode='w') as p:
20
  p.write(protein_content)
21
  protein_path = p.name
@@ -66,12 +82,7 @@ def score_wrapper(protein_file, ligand_file, cphmd, qmmm):
66
  if protein_file is None or ligand_file is None:
67
  return "Please upload both protein and ligand files"
68
 
69
- result = run_gaia(
70
- protein_file.decode('utf-8') if isinstance(protein_file, bytes) else protein_file,
71
- ligand_file.decode('utf-8') if isinstance(ligand_file, bytes) else ligand_file,
72
- cphmd,
73
- qmmm
74
- )
75
 
76
  if "error" in result:
77
  return f"❌ Error: {result['error']}"
@@ -99,8 +110,8 @@ with gr.Blocks(title="GAIA Drug Discovery", theme=gr.themes.Soft()) as demo:
99
 
100
  with gr.Row():
101
  with gr.Column():
102
- protein_input = gr.File(label="πŸ“ Protein File (PDB/PDBQT)")
103
- ligand_input = gr.File(label="πŸ“ Ligand File (PDB/PDBQT)")
104
 
105
  with gr.Row():
106
  cphmd_check = gr.Checkbox(label="🧬 Constant-pH MD", value=False)
 
14
  print(f"Device: {zero.device}")
15
 
16
  @spaces.GPU
17
+ def run_gaia(protein_file, ligand_file, use_cphmd=False, use_qmmm=False):
18
  try:
19
+ # Read the uploaded files
20
+ protein_content = protein_file
21
+ ligand_content = ligand_file
22
+
23
+ # Check if files are file objects or bytes
24
+ if hasattr(protein_file, 'read'):
25
+ protein_content = protein_file.read()
26
+ if hasattr(ligand_file, 'read'):
27
+ ligand_content = ligand_file.read()
28
+
29
+ # If bytes, decode to string
30
+ if isinstance(protein_content, bytes):
31
+ protein_content = protein_content.decode('utf-8')
32
+ if isinstance(ligand_content, bytes):
33
+ ligand_content = ligand_content.decode('utf-8')
34
+
35
  with tempfile.NamedTemporaryFile(suffix=".pdb", delete=False, mode='w') as p:
36
  p.write(protein_content)
37
  protein_path = p.name
 
82
  if protein_file is None or ligand_file is None:
83
  return "Please upload both protein and ligand files"
84
 
85
+ result = run_gaia(protein_file, ligand_file, cphmd, qmmm)
 
 
 
 
 
86
 
87
  if "error" in result:
88
  return f"❌ Error: {result['error']}"
 
110
 
111
  with gr.Row():
112
  with gr.Column():
113
+ protein_input = gr.File(label="πŸ“ Protein File (PDB/PDBQT)", file_types=[".pdb", ".pdbqt"])
114
+ ligand_input = gr.File(label="πŸ“ Ligand File (PDB/PDBQT)", file_types=[".pdb", ".pdbqt"])
115
 
116
  with gr.Row():
117
  cphmd_check = gr.Checkbox(label="🧬 Constant-pH MD", value=False)