Spaces:
Runtime error
Runtime error
Download app.py from decodingdatascience/llm-rag: direct link, hf CLI and curl.
- Browser
- Download file 867 Bytes
-
https://huggingface.co/spaces/decodingdatascience/llm-rag/resolve/main/app.py
- Command line
-
hf download hf://spaces/decodingdatascience/llm-rag/app.py
-
curl -L -o app.py https://huggingface.co/spaces/decodingdatascience/llm-rag/resolve/main/app.py
867 Bytes
| 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() | |