Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
3 |
|
4 |
-
# Load documents
|
5 |
documents = SimpleDirectoryReader("data").load_data()
|
6 |
-
index = VectorStoreIndex.from_documents(documents
|
7 |
query_engine = index.as_query_engine()
|
8 |
|
9 |
-
#
|
10 |
def query_document(query):
|
11 |
response = query_engine.query(query)
|
12 |
return str(response)
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
gr.
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
-
|
23 |
-
query_input = gr.Textbox(
|
24 |
-
label="Enter your query",
|
25 |
-
placeholder="e.g., What is the refund policy mentioned in the document?",
|
26 |
-
lines=3
|
27 |
-
)
|
28 |
-
submit_btn = gr.Button("Submit", variant="primary")
|
29 |
-
response_output = gr.Textbox(label="Response", lines=8)
|
30 |
-
|
31 |
-
submit_btn.click(fn=query_document, inputs=query_input, outputs=response_output)
|
32 |
-
|
33 |
-
# Run the app
|
34 |
if __name__ == "__main__":
|
35 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
3 |
|
4 |
+
# Load documents and build the index
|
5 |
documents = SimpleDirectoryReader("data").load_data()
|
6 |
+
index = VectorStoreIndex.from_documents(documents)
|
7 |
query_engine = index.as_query_engine()
|
8 |
|
9 |
+
# Define the function that handles the query
|
10 |
def query_document(query):
|
11 |
response = query_engine.query(query)
|
12 |
return str(response)
|
13 |
|
14 |
+
# Create a simple Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=query_document,
|
17 |
+
inputs=gr.Textbox(label="Enter your question", lines=2, placeholder="What do you want to know from the documents?"),
|
18 |
+
outputs=gr.Textbox(label="Answer"),
|
19 |
+
title="Document Q&A with LlamaIndex",
|
20 |
+
description="Ask a question and get an answer based on documents stored in the 'data' folder."
|
21 |
+
)
|
22 |
|
23 |
+
# Launch the app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
if __name__ == "__main__":
|
25 |
+
interface.launch()
|