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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -146,9 +146,16 @@ def predict(file_obj, top_kmers=10, fasta_text=""):
146
  text = fasta_text.strip()
147
  elif file_obj is not None:
148
  try:
149
- text = file_obj.decode('utf-8')
 
 
 
 
 
 
 
150
  except Exception as e:
151
- return f"Error reading file: {str(e)}", None, None
152
  else:
153
  return "Please provide a FASTA sequence either by file upload or text input.", None, None
154
 
@@ -249,7 +256,8 @@ with gr.Blocks(css=css) as iface:
249
  with gr.Column(scale=1):
250
  file_input = gr.File(
251
  label="Upload FASTA file",
252
- file_types=[".fasta", ".fa", ".txt"]
 
253
  )
254
  text_input = gr.Textbox(
255
  label="Or paste FASTA sequence",
 
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:
160
  return "Please provide a FASTA sequence either by file upload or text input.", None, None
161
 
 
256
  with gr.Column(scale=1):
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",