Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,8 @@ import gradio as gr
|
|
| 8 |
import os
|
| 9 |
from sklearn.neighbors import NearestNeighbors
|
| 10 |
|
|
|
|
|
|
|
| 11 |
def download_pdf(url, output_path):
|
| 12 |
urllib.request.urlretrieve(url, output_path)
|
| 13 |
|
|
@@ -27,6 +29,7 @@ def pdf_to_text(path, start_page=1, end_page=None):
|
|
| 27 |
|
| 28 |
text_list = []
|
| 29 |
|
|
|
|
| 30 |
for i in range(start_page-1, end_page):
|
| 31 |
text = doc.load_page(i).get_text("text")
|
| 32 |
text = preprocess(text)
|
|
@@ -153,7 +156,7 @@ def generate_answer(question,openAI_key):
|
|
| 153 |
return answer
|
| 154 |
|
| 155 |
|
| 156 |
-
def question_answer(url, file, question
|
| 157 |
if openAI_key.strip()=='':
|
| 158 |
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 159 |
if url.strip() == '' and file == None:
|
|
@@ -207,8 +210,7 @@ with gr.Blocks() as demo:
|
|
| 207 |
with gr.Group():
|
| 208 |
answer = gr.Textbox(label='The answer to your question is :')
|
| 209 |
|
| 210 |
-
|
| 211 |
-
btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
| 212 |
#openai.api_key = os.getenv('Your_Key_Here')
|
| 213 |
demo.launch()
|
| 214 |
|
|
|
|
| 8 |
import os
|
| 9 |
from sklearn.neighbors import NearestNeighbors
|
| 10 |
|
| 11 |
+
openAI_key = os.getenv('Your_Key_Here')
|
| 12 |
+
|
| 13 |
def download_pdf(url, output_path):
|
| 14 |
urllib.request.urlretrieve(url, output_path)
|
| 15 |
|
|
|
|
| 29 |
|
| 30 |
text_list = []
|
| 31 |
|
| 32 |
+
|
| 33 |
for i in range(start_page-1, end_page):
|
| 34 |
text = doc.load_page(i).get_text("text")
|
| 35 |
text = preprocess(text)
|
|
|
|
| 156 |
return answer
|
| 157 |
|
| 158 |
|
| 159 |
+
def question_answer(url, file, question):
|
| 160 |
if openAI_key.strip()=='':
|
| 161 |
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 162 |
if url.strip() == '' and file == None:
|
|
|
|
| 210 |
with gr.Group():
|
| 211 |
answer = gr.Textbox(label='The answer to your question is :')
|
| 212 |
|
| 213 |
+
btn.click(question_answer, inputs=[url, file, question], outputs=[answer])
|
|
|
|
| 214 |
#openai.api_key = os.getenv('Your_Key_Here')
|
| 215 |
demo.launch()
|
| 216 |
|