Add demo.py
Browse files
demo.py
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
-
"""
|
| 2 |
-
ZamAI Embeddings Demo Application
|
| 3 |
-
This script creates a web interface for querying documents using multilingual embeddings.
|
| 4 |
-
"""
|
| 5 |
-
import gradio as gr
|
| 6 |
-
from setup import setup_embedding_model
|
| 7 |
-
|
| 8 |
-
# Set up the embedding model and query engine
|
| 9 |
-
print("Setting up embedding model and vector database...")
|
| 10 |
-
embedding_components = setup_embedding_model()
|
| 11 |
-
query_engine = embedding_components["query_engine"]
|
| 12 |
-
|
| 13 |
-
# Define the query function
|
| 14 |
-
def answer_query(query):
|
| 15 |
-
"""Process a user query and return relevant information from indexed documents"""
|
| 16 |
-
if not query.strip():
|
| 17 |
-
return "Please enter a query."
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
result = query_engine.query(query)
|
| 21 |
-
return str(result)
|
| 22 |
-
except Exception as e:
|
| 23 |
-
return f"Error processing query: {str(e)}"
|
| 24 |
-
|
| 25 |
-
# Create the Gradio interface
|
| 26 |
-
iface = gr.Interface(
|
| 27 |
-
fn=answer_query,
|
| 28 |
-
inputs=gr.Textbox(lines=2, placeholder="Ask in any language (English, Pashto, etc.)"),
|
| 29 |
-
outputs="text",
|
| 30 |
-
title="ZamAI Multilingual Embeddings Demo",
|
| 31 |
-
description="Ask questions about your documents in any language, including Pashto and English."
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
print("Starting Gradio web interface...")
|
| 36 |
-
iface.launch()
|
| 37 |
-
print("Interface closed.")
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ZamAI Embeddings Demo Application
|
| 3 |
+
This script creates a web interface for querying documents using multilingual embeddings.
|
| 4 |
+
"""
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from setup import setup_embedding_model
|
| 7 |
+
|
| 8 |
+
# Set up the embedding model and query engine
|
| 9 |
+
print("Setting up embedding model and vector database...")
|
| 10 |
+
embedding_components = setup_embedding_model()
|
| 11 |
+
query_engine = embedding_components["query_engine"]
|
| 12 |
+
|
| 13 |
+
# Define the query function
|
| 14 |
+
def answer_query(query):
|
| 15 |
+
"""Process a user query and return relevant information from indexed documents"""
|
| 16 |
+
if not query.strip():
|
| 17 |
+
return "Please enter a query."
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
result = query_engine.query(query)
|
| 21 |
+
return str(result)
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return f"Error processing query: {str(e)}"
|
| 24 |
+
|
| 25 |
+
# Create the Gradio interface
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=answer_query,
|
| 28 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask in any language (English, Pashto, etc.)"),
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="ZamAI Multilingual Embeddings Demo",
|
| 31 |
+
description="Ask questions about your documents in any language, including Pashto and English."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
print("Starting Gradio web interface...")
|
| 36 |
+
iface.launch()
|
| 37 |
+
print("Interface closed.")
|