Spaces:
Runtime error
Runtime error
adding application files
Browse files- .env +1 -0
- app.py +26 -0
- requirements.txt +4 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY = 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
|
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from llama_index import GPTVectorStoreIndex, download_loader
|
5 |
+
import openai
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
+
|
11 |
+
UnstructuredReader = download_loader('UnstructuredReader', refresh_cache=True)
|
12 |
+
loader = UnstructuredReader()
|
13 |
+
|
14 |
+
def answer_question(pdf, question):
|
15 |
+
data = loader.load_data(pdf.name, split_documents=False)
|
16 |
+
index = GPTVectorStoreIndex.from_documents(data)
|
17 |
+
query_engine = index.as_query_engine()
|
18 |
+
response = query_engine.query(question)
|
19 |
+
return response
|
20 |
+
|
21 |
+
iface = gr.Interface(fn=answer_question,
|
22 |
+
inputs=[gr.File(label="Upload a PDF file"),
|
23 |
+
gr.Textbox(label="Enter your question")],
|
24 |
+
outputs="text")
|
25 |
+
|
26 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
python-dotenv
|
3 |
+
llama-index
|
4 |
+
openai
|