Spaces:
Runtime error
Runtime error
Commit
·
ced6c28
1
Parent(s):
ed754c5
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import openai
|
|
7 |
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)
|
@@ -155,14 +157,18 @@ def question_answer(url, file, question,openAI_key):
|
|
155 |
|
156 |
if question.strip() == '':
|
157 |
return '[ERROR]: Question field is empty'
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
return
|
160 |
|
161 |
|
162 |
recommender = SemanticSearch()
|
163 |
|
164 |
title = 'PDF GPT'
|
165 |
-
description = """
|
166 |
|
167 |
with gr.Blocks() as demo:
|
168 |
|
@@ -170,10 +176,10 @@ with gr.Blocks() as demo:
|
|
170 |
gr.Markdown(description)
|
171 |
|
172 |
with gr.Row():
|
173 |
-
|
174 |
with gr.Group():
|
175 |
gr.Markdown(f'<p style="text-align:center">Get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a></p>')
|
176 |
-
openAI_key=gr.Textbox(label='Enter your OpenAI API key here')
|
177 |
url = gr.Textbox(label='Enter PDF URL here')
|
178 |
gr.Markdown("<center><h4>OR<h4></center>")
|
179 |
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
@@ -184,6 +190,6 @@ with gr.Blocks() as demo:
|
|
184 |
with gr.Group():
|
185 |
answer = gr.Textbox(label='The answer to your question is :')
|
186 |
|
187 |
-
btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
188 |
-
|
189 |
-
demo.launch()
|
|
|
7 |
import gradio as gr
|
8 |
import os
|
9 |
from sklearn.neighbors import NearestNeighbors
|
10 |
+
from gradio.mix import Interface
|
11 |
+
|
12 |
|
13 |
def download_pdf(url, output_path):
|
14 |
urllib.request.urlretrieve(url, output_path)
|
|
|
157 |
|
158 |
if question.strip() == '':
|
159 |
return '[ERROR]: Question field is empty'
|
160 |
+
|
161 |
+
answer = generate_answer(question,openAI_key)
|
162 |
+
# Convert answer to HTML with clickable citations
|
163 |
+
answer_html = re.sub(r'\[(\d+)\]', r'<a href="#" onclick="navigateToPage(\1)">[\1]</a>', answer)
|
164 |
|
165 |
+
return answer_html
|
166 |
|
167 |
|
168 |
recommender = SemanticSearch()
|
169 |
|
170 |
title = 'PDF GPT'
|
171 |
+
description = """PDF GPT allows you to chat with your PDF file using Universal Sentence Encoder and Open AI. It gives hallucination-free response than other tools as the embeddings are better than OpenAI. The returned response can even cite the page number in square brackets([]) where the information is located, adding credibility to the responses and helping to locate pertinent information quickly."""
|
172 |
|
173 |
with gr.Blocks() as demo:
|
174 |
|
|
|
176 |
gr.Markdown(description)
|
177 |
|
178 |
with gr.Row():
|
179 |
+
|
180 |
with gr.Group():
|
181 |
gr.Markdown(f'<p style="text-align:center">Get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a></p>')
|
182 |
+
openAI_key = gr.Textbox(label='Enter your OpenAI API key here')
|
183 |
url = gr.Textbox(label='Enter PDF URL here')
|
184 |
gr.Markdown("<center><h4>OR<h4></center>")
|
185 |
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
|
|
190 |
with gr.Group():
|
191 |
answer = gr.Textbox(label='The answer to your question is :')
|
192 |
|
193 |
+
btn.click(question_answer, inputs=[url, file, question, openAI_key], outputs=[answer])
|
194 |
+
|
195 |
+
demo.launch()
|