Spaces:
Sleeping
Sleeping
import gradio as gr | |
from utils.credentials import check_credentials, init_clients | |
from ui.embeddings_tab import create_embeddings_tab | |
from ui.search_tab import create_search_tab | |
def create_app(): | |
"""Create and configure the Gradio application""" | |
with gr.Blocks(title="MongoDB Vector Search Tool") as iface: | |
gr.Markdown("# MongoDB Vector Search Tool") | |
# Check credentials first | |
has_creds, cred_message = check_credentials() | |
if not has_creds: | |
gr.Markdown(f""" | |
## ⚠️ Setup Required | |
{cred_message} | |
After setting up credentials, refresh this page. | |
""") | |
else: | |
# Initialize clients | |
openai_client, db_utils = init_clients() | |
if not openai_client or not db_utils: | |
gr.Markdown(""" | |
## ⚠️ Connection Error | |
Failed to connect to MongoDB Atlas or OpenAI. Please check your credentials and try again. | |
""") | |
else: | |
# Get available databases | |
try: | |
databases = db_utils.get_databases() | |
except Exception as e: | |
gr.Markdown(f""" | |
## ⚠️ Database Error | |
Failed to list databases: {str(e)} | |
Please check your MongoDB Atlas connection and try again. | |
""") | |
databases = [] | |
# Create tabs | |
embeddings_tab, embeddings_interface = create_embeddings_tab( | |
openai_client=openai_client, | |
db_utils=db_utils, | |
databases=databases | |
) | |
search_tab, search_interface = create_search_tab( | |
openai_client=openai_client, | |
db_utils=db_utils, | |
databases=databases | |
) | |
return iface | |
if __name__ == "__main__": | |
app = create_app() | |
app.launch(server_name="0.0.0.0") | |