mawairon commited on
Commit
fe4ceb1
1 Parent(s): 9bf3f2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -63,10 +63,10 @@ model, tokenizer = load_model()
63
  def analyze_dna(sequence):
64
  try:
65
  if not all(nucleotide in 'ACTGN' for nucleotide in sequence):
66
- return "Error: Sequence contains invalid characters", ""
67
 
68
  if len(sequence) < 300:
69
- return "Error: Sequence needs to be at least 300 nucleotides long", ""
70
 
71
  inputs = tokenizer(sequence, truncation=True, padding='max_length', max_length=512, return_tensors="pt", return_token_type_ids=False)
72
  logits = model(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'])
@@ -92,7 +92,7 @@ def analyze_dna(sequence):
92
  return result, f'<img src="data:image/png;base64,{image_base64}" />'
93
 
94
  except Exception as e:
95
- return str(e), ""
96
 
97
  # Create a Gradio interface
98
  demo = gr.Interface(fn=analyze_dna, inputs="text", outputs=["json", "html"])
 
63
  def analyze_dna(sequence):
64
  try:
65
  if not all(nucleotide in 'ACTGN' for nucleotide in sequence):
66
+ return {"error": "Sequence contains invalid characters"}, ""
67
 
68
  if len(sequence) < 300:
69
+ return {"error": "Sequence needs to be at least 300 nucleotides long"}, ""
70
 
71
  inputs = tokenizer(sequence, truncation=True, padding='max_length', max_length=512, return_tensors="pt", return_token_type_ids=False)
72
  logits = model(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'])
 
92
  return result, f'<img src="data:image/png;base64,{image_base64}" />'
93
 
94
  except Exception as e:
95
+ return {"error": str(e)}, ""
96
 
97
  # Create a Gradio interface
98
  demo = gr.Interface(fn=analyze_dna, inputs="text", outputs=["json", "html"])