File size: 1,306 Bytes
a318724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import argparse
import os
import sys
import gradio as gr
from utils import load_embeddings
from ui import create_demo, embeddings

def main():
    """Main entry point for the application"""
    parser = argparse.ArgumentParser(description='Run the Product Categorization web app')
    parser.add_argument('--embeddings', default='ingredient_embeddings_voyageai.pkl', 
                        help='Path to the ingredient embeddings pickle file')
    parser.add_argument('--share', action='store_true', help='Create a public link for sharing')
    
    args = parser.parse_args()
    
    # Check if embeddings file exists
    if not os.path.exists(args.embeddings):
        print(f"Error: Embeddings file {args.embeddings} not found!")
        print(f"Please ensure the file exists at {os.path.abspath(args.embeddings)}")
        sys.exit(1)
    
    # Load embeddings
    try:
        global embeddings
        embeddings_data = load_embeddings(args.embeddings)
        # Update the embeddings in the ui module
        import ui
        ui.embeddings = embeddings_data
    except Exception as e:
        print(f"Error loading embeddings: {e}")
        sys.exit(1)
    
    # Create and launch the interface
    demo = create_demo()
    demo.launch(share=args.share)

if __name__ == "__main__":
    main()