File size: 756 Bytes
6a7403c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
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)