freexyan commited on
Commit
02db908
·
1 Parent(s): c168f34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -46
app.py CHANGED
@@ -8,8 +8,6 @@ import gradio as gr
8
  import os
9
  from sklearn.neighbors import NearestNeighbors
10
 
11
- openai.api_key = os.getenv('Your_Key_Here')
12
-
13
  def download_pdf(url, output_path):
14
  urllib.request.urlretrieve(url, output_path)
15
 
@@ -56,7 +54,6 @@ def text_to_chunks(texts, word_length=150, start_page=1):
56
  return chunks
57
 
58
 
59
-
60
  class SemanticSearch:
61
 
62
  def __init__(self):
@@ -190,49 +187,53 @@ description = """ What is PDF GPT ?
190
  1. The problem is that Open AI has a 4K token limit and cannot take an entire PDF file as input. Additionally, it sometimes returns irrelevant responses due to poor embeddings. ChatGPT cannot directly talk to external data. The solution is PDF GPT, which allows you to chat with an uploaded PDF file using GPT functionalities. The application breaks the document into smaller chunks and generates embeddings using a powerful Deep Averaging Network Encoder. A semantic search is performed on your query, and the top relevant chunks are used to generate a response.
191
  2. 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. The Responses are much better than the naive responses by Open AI."""
192
 
193
- # with gr.Blocks() as demo:
194
 
195
- # gr.Markdown(f'<center><h1>{title}</h1></center>')
196
- # gr.Markdown(description)
197
 
198
- # with gr.Row():
199
 
200
- # with gr.Group():
201
- # url = gr.Textbox(label='Enter PDF URL here')
202
- # gr.Markdown("<center><h4>OR<h4></center>")
203
- # file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
204
- # question = gr.Textbox(label='Enter your question here')
205
- # btn = gr.Button(value='Submit')
206
- # btn.style(full_width=True)
207
-
208
- # with gr.Group():
209
- # answer = gr.Textbox(label='The answer to your question is :')
210
-
211
- # openai.api_key = os.getenv('Your_Key_Here')
212
- # btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
213
- # demo.launch()
214
-
215
- import streamlit as st
216
-
217
- #Define the app layout
218
- st.markdown(f'<center><h1>{title}</h1></center>', unsafe_allow_html=True)
219
- st.markdown(description)
220
-
221
- col1, col2 = st.columns(2)
222
-
223
- # Define the inputs in the first column
224
- with col1:
225
- url = st.text_input('URL')
226
- st.markdown("<center><h6>or<h6></center>", unsafe_allow_html=True)
227
- file = st.file_uploader('PDF', type='pdf')
228
- question = st.text_input('question')
229
- btn = st.button('Submit')
230
-
231
- # Define the output in the second column
232
- with col2:
233
- answer = st.text_input('answer')
234
-
235
- # Define the button action
236
- if btn:
237
- answer_value = question_answer(url, file, question)
238
- answer.value = answer_value
 
 
 
 
 
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
 
 
54
  return chunks
55
 
56
 
 
57
  class SemanticSearch:
58
 
59
  def __init__(self):
 
187
  1. The problem is that Open AI has a 4K token limit and cannot take an entire PDF file as input. Additionally, it sometimes returns irrelevant responses due to poor embeddings. ChatGPT cannot directly talk to external data. The solution is PDF GPT, which allows you to chat with an uploaded PDF file using GPT functionalities. The application breaks the document into smaller chunks and generates embeddings using a powerful Deep Averaging Network Encoder. A semantic search is performed on your query, and the top relevant chunks are used to generate a response.
188
  2. 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. The Responses are much better than the naive responses by Open AI."""
189
 
190
+ with gr.Blocks() as demo:
191
 
192
+ gr.Markdown(f'<center><h1>{title}</h1></center>')
193
+ gr.Markdown(description)
194
 
195
+ with gr.Row():
196
 
197
+ with gr.Group():
198
+ # 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>')
199
+ # openAI_key=gr.Textbox(label='Enter your OpenAI API key here')
200
+ url = gr.Textbox(label='Enter PDF URL here')
201
+ gr.Markdown("<center><h4>OR<h4></center>")
202
+ file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
203
+ question = gr.Textbox(label='Enter your question here')
204
+ btn = gr.Button(value='Submit')
205
+ btn.style(full_width=True)
206
+
207
+ with gr.Group():
208
+ answer = gr.Textbox(label='The answer to your question is :')
209
+
210
+ openAI_key = os.getenv('Your_Key_Here')
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
+
215
+
216
+ # import streamlit as st
217
+
218
+ # #Define the app layout
219
+ # st.markdown(f'<center><h1>{title}</h1></center>', unsafe_allow_html=True)
220
+ # st.markdown(description)
221
+
222
+ # col1, col2 = st.columns(2)
223
+
224
+ # # Define the inputs in the first column
225
+ # with col1:
226
+ # url = st.text_input('URL')
227
+ # st.markdown("<center><h6>or<h6></center>", unsafe_allow_html=True)
228
+ # file = st.file_uploader('PDF', type='pdf')
229
+ # question = st.text_input('question')
230
+ # btn = st.button('Submit')
231
+
232
+ # # Define the output in the second column
233
+ # with col2:
234
+ # answer = st.text_input('answer')
235
+
236
+ # # Define the button action
237
+ # if btn:
238
+ # answer_value = question_answer(url, file, question)
239
+ # answer.value = answer_value