epipred2 / test_enhanced_app.py
mercelv's picture
app
d640b1c verified
Raw
History Blame Contribute Delete
2.61 kB
#!/usr/bin/env python3
"""
Test script for enhanced Gradio app
"""
import sys
import os
def test_enhanced_app():
"""Test the enhanced Gradio app"""
print("πŸ§ͺ Testing Enhanced Gradio App")
print("=" * 40)
try:
# Test imports
print("Testing imports...")
import pandas as pd
import numpy as np
print("βœ… Core libraries imported")
# Test model predictor
print("\nTesting model predictor...")
from model_predictor import EpitopePredictor
predictor = EpitopePredictor()
print(f"βœ… Model predictor loaded (model available: {predictor.model is not None})")
# Test app functions
print("\nTesting app functions...")
from app_gradio_simple import parse_fasta_text, validate_sequences, format_sequence_with_epitopes
# Test FASTA parsing
test_fasta = """>Test_Seq
MKLLILTCLVAVALARPKHPIKHQGLPQEVLNENLLRFFVAPFPEVFGKEKVNEL"""
sequences = parse_fasta_text(test_fasta)
print(f"βœ… FASTA parsing: {len(sequences)} sequences parsed")
# Test validation
errors = validate_sequences(sequences)
print(f"βœ… Sequence validation: {len(errors)} errors found")
# Test sequence formatting
test_seq = list(sequences.values())[0]
b_epitopes = [("MKLLILTCLVA", 0.8, "1-11")]
t_epitopes = [("LARPKHPIKHQ", 0.7, "12-22")]
formatted = format_sequence_with_epitopes(test_seq, b_epitopes, t_epitopes)
print(f"βœ… Sequence formatting: {len(formatted)} characters")
# Test prediction function
print("\nTesting prediction function...")
from app_gradio_simple import predict_epitopes
result = predict_epitopes(test_fasta, None, 0.5)
print(f"βœ… Prediction function: {len(result)} outputs returned")
# Test interface creation
print("\nTesting interface creation...")
from app_gradio_simple import create_interface
demo = create_interface()
print(f"βœ… Interface created: {type(demo)}")
print("\n" + "=" * 40)
print("πŸŽ‰ All tests passed! Enhanced app is ready.")
return True
except ImportError as e:
print(f"❌ Import error: {e}")
print("Note: This is expected if Gradio is not installed locally")
return False
except Exception as e:
print(f"❌ Error: {e}")
return False
if __name__ == '__main__':
success = test_enhanced_app()
sys.exit(0 if success else 1)