File size: 867 Bytes
35a4aa1
 
 
60abb2d
35a4aa1
60abb2d
35a4aa1
 
60abb2d
35a4aa1
 
 
 
60abb2d
 
 
 
 
 
 
 
35a4aa1
60abb2d
35a4aa1
60abb2d
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
import gradio as gr
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

# Load documents and build the index
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()

# Define the function that handles the query
def query_document(query):
    response = query_engine.query(query)
    return str(response)

# Create a simple Gradio interface
interface = gr.Interface(
    fn=query_document,
    inputs=gr.Textbox(label="Enter your question", lines=2, placeholder="What do you want to know from the documents?"),
    outputs=gr.Textbox(label="Answer"),
    title="Document Q&A with LlamaIndex",
    description="Ask a question and get an answer based on documents stored in the 'data' folder."
)

# Launch the app
if __name__ == "__main__":
    interface.launch()