File size: 2,274 Bytes
e055374 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | # ============================================================================
# MAIN APPLICATION ENTRY POINT
# ============================================================================
# This is the main entry point for the Hindi BPE Encoder application.
# It orchestrates all components: tokenizer, handlers, and UI.
# Import the tokenizer class
from hindi_bpe_encoder import HindiBPEEncoder
# Import Gradio handlers (wrapper functions)
from gradio_handlers import (
create_encode_handler,
create_decode_handler
)
# Import UI builder
from gradio_ui import create_app_interface
# ============================================================================
# INITIALIZATION
# ============================================================================
# Create a single global instance of the encoder
# This instance is shared across all Gradio interface functions
# The tokenizer state persists throughout the app's lifetime
encoder = HindiBPEEncoder()
# Create handler functions bound to the encoder instance
# These functions connect the tokenizer to the Gradio UI
encode_handler = create_encode_handler(encoder)
decode_handler = create_decode_handler(encoder)
# ============================================================================
# APP CREATION
# ============================================================================
# Create the complete Gradio application interface
# This combines all UI components with their respective handlers
demo = create_app_interface(
encoder=encoder,
encode_handler=encode_handler,
decode_handler=decode_handler
)
# ============================================================================
# APP LAUNCH
# ============================================================================
# This block runs when the script is executed directly (not imported)
if __name__ == "__main__":
# Launch the Gradio app
# server_name="0.0.0.0": Listen on all network interfaces
# Allows access from other devices on network
# Required for Hugging Face Spaces deployment
# server_port=7860: Default port for Gradio apps
# Also the default port for Hugging Face Spaces
demo.launch(server_name="0.0.0.0", server_port=7860)
|