|
|
|
|
|
"""
|
|
|
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()
|
|
|
|
|
|
|
|
|
try:
|
|
|
from app import create_interface
|
|
|
print("Loading ABSA models... This may take a few minutes on first run.")
|
|
|
demo = create_interface()
|
|
|
|
|
|
|
|
|
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!")
|
|
|
|
|
|
|
|
|
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() |