ABSA / run.py
sdf299's picture
Upload folder using huggingface_hub
f05ed74 verified
#!/usr/bin/env python3
"""
Simple launcher script for the ABSA Gradio application.
Provides different launch options for various use cases.
"""
import argparse
import sys
import os
def main():
parser = argparse.ArgumentParser(description="Launch the ABSA Gradio Application")
parser.add_argument(
'--mode',
choices=['dev', 'prod', 'share'],
default='dev',
help='Launch mode: dev (development), prod (production), share (public link)'
)
parser.add_argument('--port', type=int, default=7860, help='Port to run the server on')
parser.add_argument('--host', default='127.0.0.1', help='Host to bind to')
args = parser.parse_args()
# Import here to avoid loading models during argument parsing
try:
from app import create_interface
print("Loading ABSA models... This may take a few minutes on first run.")
demo = create_interface()
# Configure launch parameters based on mode
launch_kwargs = {
'server_port': args.port,
'show_error': True
}
if args.mode == 'dev':
launch_kwargs.update({
'server_name': '127.0.0.1',
'share': False,
'debug': True
})
print(f"πŸš€ Starting in DEVELOPMENT mode on http://127.0.0.1:{args.port}")
elif args.mode == 'prod':
launch_kwargs.update({
'server_name': '0.0.0.0',
'share': False,
'debug': False
})
print(f"πŸš€ Starting in PRODUCTION mode on http://0.0.0.0:{args.port}")
elif args.mode == 'share':
launch_kwargs.update({
'server_name': '0.0.0.0',
'share': True,
'debug': False
})
print("πŸš€ Starting with PUBLIC LINK (share=True)")
print("⚠️ The public link will be accessible from anywhere on the internet!")
# Launch the application
demo.launch(**launch_kwargs)
except ImportError as e:
print(f"❌ Error importing required modules: {e}")
print("πŸ’‘ Make sure you've installed the requirements: pip install -r requirements.txt")
sys.exit(1)
except Exception as e:
print(f"❌ Error starting the application: {e}")
sys.exit(1)
if __name__ == "__main__":
main()