| """ | |
| ZamAI Embeddings Demo Application | |
| This script creates a web interface for querying documents using multilingual embeddings. | |
| """ | |
| import gradio as gr | |
| from setup import setup_embedding_model | |
| # Set up the embedding model and query engine | |
| print("Setting up embedding model and vector database...") | |
| embedding_components = setup_embedding_model() | |
| query_engine = embedding_components["query_engine"] | |
| # Define the query function | |
| def answer_query(query): | |
| """Process a user query and return relevant information from indexed documents""" | |
| if not query.strip(): | |
| return "Please enter a query." | |
| try: | |
| result = query_engine.query(query) | |
| return str(result) | |
| except Exception as e: | |
| return f"Error processing query: {str(e)}" | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=answer_query, | |
| inputs=gr.Textbox(lines=2, placeholder="Ask in any language (English, Pashto, etc.)"), | |
| outputs="text", | |
| title="ZamAI Multilingual Embeddings Demo", | |
| description="Ask questions about your documents in any language, including Pashto and English." | |
| ) | |
| if __name__ == "__main__": | |
| print("Starting Gradio web interface...") | |
| iface.launch() | |
| print("Interface closed.") | |