AbMelt_HF_Space_Taher / run_local.py
AhmedElTaher's picture
Upload 10 files
0e26454 verified
#!/usr/bin/env python3
"""
Simple script to run AbMelt pipeline locally for testing
"""
import os
import sys
from pathlib import Path
import json
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
def load_example_sequences():
"""Load example antibody sequences"""
example_file = Path(__file__).parent / "data" / "example_antibodies.json"
if example_file.exists():
with open(example_file, 'r') as f:
data = json.load(f)
return data['test_antibodies']
else:
# Fallback sequences
return [
{
"name": "Test Antibody",
"heavy_chain": "QVQLVQSGAEVKKPGASVKVSCKASGYTFTSYYMHWVRQAPGQGLEWMGIINPSGGSTNYAQKFQGRVTMTRDTSASTAYMELSSLRSEDTAVYYCAR",
"light_chain": "DIQMTQSPSSLSASVGDRVTITCRASQSISSYLNWYQQKPGKAPKLLIYAASSLQSGVPSRFSGSGSGTDFTLTISSLQPEDFATYYCQQSYST"
}
]
def run_validation():
"""Run pipeline validation"""
print("πŸ§ͺ Running AbMelt Pipeline Validation...")
print("=" * 50)
try:
import test_pipeline
success = test_pipeline.run_all_tests()
if success:
print("πŸŽ‰ All validation tests passed!")
print("βœ… Pipeline is ready to use")
return True
else:
print("❌ Some validation tests failed")
print("⚠️ Check logs above for details")
return False
except Exception as e:
print(f"❌ Validation failed with error: {e}")
return False
def run_gradio_app():
"""Run the Gradio application"""
print("πŸš€ Starting AbMelt Gradio Interface...")
print("πŸ“± Open your browser to: http://localhost:7860")
print("⏹️ Press Ctrl+C to stop")
print("=" * 50)
try:
import app
# The app.py file will handle the launch
pass
except KeyboardInterrupt:
print("\\nπŸ‘‹ Shutting down...")
except Exception as e:
print(f"❌ Failed to start Gradio app: {e}")
def show_example_sequences():
"""Display example sequences for testing"""
print("🧬 Example Antibody Sequences for Testing:")
print("=" * 50)
examples = load_example_sequences()
for i, antibody in enumerate(examples, 1):
print(f"\\n{i}. {antibody['name']}")
print(f" Target: {antibody.get('target', 'Unknown')}")
print(f" Heavy Chain: {antibody['heavy_chain'][:50]}...")
print(f" Light Chain: {antibody['light_chain'][:50]}...")
if 'description' in antibody:
print(f" Description: {antibody['description']}")
def main():
"""Main entry point"""
print("🧬 AbMelt Pipeline - Local Runner")
print("=" * 50)
if len(sys.argv) > 1:
command = sys.argv[1].lower()
else:
print("Available commands:")
print(" python run_local.py test - Run validation tests")
print(" python run_local.py run - Start Gradio interface")
print(" python run_local.py examples - Show example sequences")
print(" python run_local.py help - Show this help")
return
if command == "test" or command == "validate":
run_validation()
elif command == "run" or command == "start":
# First run quick validation
print("πŸ” Quick validation check...")
if run_validation():
print("\\n" + "=" * 50)
run_gradio_app()
else:
print("\\n❌ Validation failed. Please fix issues before running the app.")
elif command == "examples":
show_example_sequences()
elif command == "help" or command == "--help":
print("AbMelt Pipeline Local Runner")
print("\\nCommands:")
print(" test/validate - Run all validation tests")
print(" run/start - Start the Gradio web interface")
print(" examples - Show example antibody sequences")
print(" help - Show this help message")
print("\\nUsage:")
print(" python run_local.py test")
print(" python run_local.py run")
else:
print(f"❌ Unknown command: {command}")
print("Run 'python run_local.py help' for available commands")
if __name__ == "__main__":
main()