hiyata commited on
Commit
0681a74
·
verified ·
1 Parent(s): 8f84058

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -146,14 +146,9 @@ def predict(file_obj, top_kmers=10, fasta_text=""):
146
  text = fasta_text.strip()
147
  elif file_obj is not None:
148
  try:
149
- # Handle file reading based on type
150
- if hasattr(file_obj, 'name'): # Gradio returns a temp file
151
- with open(file_obj.name, 'r') as f:
152
- text = f.read()
153
- elif isinstance(file_obj, str): # Already a string
154
- text = file_obj
155
- else: # Try reading as bytes
156
- text = file_obj.read().decode('utf-8')
157
  except Exception as e:
158
  return f"Error reading file: {str(e)}\nPlease ensure you're uploading a valid FASTA text file.", None, None
159
  else:
@@ -257,7 +252,7 @@ with gr.Blocks(css=css) as iface:
257
  file_input = gr.File(
258
  label="Upload FASTA file",
259
  file_types=[".fasta", ".fa", ".txt"],
260
- type="file" # Explicitly specify file type
261
  )
262
  text_input = gr.Textbox(
263
  label="Or paste FASTA sequence",
 
146
  text = fasta_text.strip()
147
  elif file_obj is not None:
148
  try:
149
+ # File input will be a filepath since we specified type="filepath"
150
+ with open(file_obj, 'r') as f:
151
+ text = f.read()
 
 
 
 
 
152
  except Exception as e:
153
  return f"Error reading file: {str(e)}\nPlease ensure you're uploading a valid FASTA text file.", None, None
154
  else:
 
252
  file_input = gr.File(
253
  label="Upload FASTA file",
254
  file_types=[".fasta", ".fa", ".txt"],
255
+ type="filepath" # Changed to filepath which is one of the valid options
256
  )
257
  text_input = gr.Textbox(
258
  label="Or paste FASTA sequence",