esilver's picture
refactored
a318724
raw
history blame
1.31 kB
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()