Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
| 3 |
+
import openai
|
| 4 |
+
import json
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
+
documents = SimpleDirectoryReader("data").load_data()
|
| 11 |
+
index = VectorStoreIndex.from_documents(documents=documents)
|
| 12 |
+
query_engine = index.as_query_engine()
|
| 13 |
+
|
| 14 |
+
# Function to handle queries
|
| 15 |
+
def query_document(message,history):
|
| 16 |
+
response = query_engine.query(message)
|
| 17 |
+
return str(response)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
interface = gr.ChatInterface(fn=query_document
|
| 21 |
+
,textbox=gr.Textbox(placeholder="Ask any information from DDS HR documents!")
|
| 22 |
+
,title="DDS Document Bot", description="Ask about the DDS HR Policy!")
|
| 23 |
+
|
| 24 |
+
interface.launch(debug=True)
|
| 25 |
+
|
| 26 |
+
|