murtaza2k's picture
Create app.py
6a7403c verified
raw
history blame contribute delete
756 Bytes
import gradio as gr
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
import openai
import json
from dotenv import load_dotenv
import os
openai.api_key = os.getenv("OPENAI_API_KEY")
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents=documents)
query_engine = index.as_query_engine()
# Function to handle queries
def query_document(message,history):
response = query_engine.query(message)
return str(response)
interface = gr.ChatInterface(fn=query_document
,textbox=gr.Textbox(placeholder="Ask any information from DDS HR documents!")
,title="DDS Document Bot", description="Ask about the DDS HR Policy!")
interface.launch(debug=True)