Spaces:
Sleeping
Sleeping
Commit ·
37f663f
1
Parent(s): dbc1154
update
Browse files
app.py
CHANGED
|
@@ -99,8 +99,8 @@ def load_recommender(path, start_page=1):
|
|
| 99 |
return 'Corpus Loaded.'
|
| 100 |
|
| 101 |
|
| 102 |
-
def generate_text(
|
| 103 |
-
openai.api_key =
|
| 104 |
completions = openai.Completion.create(
|
| 105 |
engine=engine,
|
| 106 |
prompt=prompt,
|
|
@@ -113,7 +113,7 @@ def generate_text(openAI_key,prompt, engine="text-davinci-003"):
|
|
| 113 |
return message
|
| 114 |
|
| 115 |
|
| 116 |
-
def generate_answer(question
|
| 117 |
topn_chunks = recommender(question)
|
| 118 |
prompt = ""
|
| 119 |
prompt += 'search results:\n\n'
|
|
@@ -130,13 +130,11 @@ def generate_answer(question,openAI_key):
|
|
| 130 |
"answer should be short and concise. \n\nQuery: {question}\nAnswer: "
|
| 131 |
|
| 132 |
prompt += f"Query: {question}\nAnswer:"
|
| 133 |
-
answer = generate_text(
|
| 134 |
return answer
|
| 135 |
|
| 136 |
|
| 137 |
-
def question_answer(url, file, question
|
| 138 |
-
if openAI_key.strip()=='':
|
| 139 |
-
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 140 |
if url.strip() == '' and file == None:
|
| 141 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
| 142 |
|
|
@@ -158,13 +156,13 @@ def question_answer(url, file, question,openAI_key):
|
|
| 158 |
if question.strip() == '':
|
| 159 |
return '[ERROR]: Question field is empty'
|
| 160 |
|
| 161 |
-
return generate_answer(question
|
| 162 |
|
| 163 |
|
| 164 |
recommender = SemanticSearch()
|
| 165 |
|
| 166 |
title = 'CauseWriter PDF'
|
| 167 |
-
description = """ PDF GPT allows you to chat with your PDF file using Universal Sentence Encoder and Open AI. It gives hallucination
|
| 168 |
|
| 169 |
|
| 170 |
with gr.Blocks() as demo:
|
|
@@ -175,8 +173,6 @@ with gr.Blocks() as demo:
|
|
| 175 |
with gr.Row():
|
| 176 |
|
| 177 |
with gr.Group():
|
| 178 |
-
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>')
|
| 179 |
-
openAI_key = os.environ['Your_Key_Here']
|
| 180 |
url = gr.Textbox(label='Enter PDF URL here')
|
| 181 |
gr.Markdown("<center><h4>OR<h4></center>")
|
| 182 |
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
|
@@ -187,7 +183,6 @@ with gr.Blocks() as demo:
|
|
| 187 |
with gr.Group():
|
| 188 |
answer = gr.Textbox(label='The answer to your question is :')
|
| 189 |
|
| 190 |
-
btn.click(question_answer, inputs=[url, file, question
|
| 191 |
-
openai.api_key = os.environ['Your_Key_Here']
|
| 192 |
-
demo.launch()
|
| 193 |
|
|
|
|
|
|
| 99 |
return 'Corpus Loaded.'
|
| 100 |
|
| 101 |
|
| 102 |
+
def generate_text(prompt, engine="text-davinci-003"):
|
| 103 |
+
openai.api_key = os.getenv('Your_Key_Here')
|
| 104 |
completions = openai.Completion.create(
|
| 105 |
engine=engine,
|
| 106 |
prompt=prompt,
|
|
|
|
| 113 |
return message
|
| 114 |
|
| 115 |
|
| 116 |
+
def generate_answer(question):
|
| 117 |
topn_chunks = recommender(question)
|
| 118 |
prompt = ""
|
| 119 |
prompt += 'search results:\n\n'
|
|
|
|
| 130 |
"answer should be short and concise. \n\nQuery: {question}\nAnswer: "
|
| 131 |
|
| 132 |
prompt += f"Query: {question}\nAnswer:"
|
| 133 |
+
answer = generate_text(prompt,"text-davinci-003")
|
| 134 |
return answer
|
| 135 |
|
| 136 |
|
| 137 |
+
def question_answer(url, file, question):
|
|
|
|
|
|
|
| 138 |
if url.strip() == '' and file == None:
|
| 139 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
| 140 |
|
|
|
|
| 156 |
if question.strip() == '':
|
| 157 |
return '[ERROR]: Question field is empty'
|
| 158 |
|
| 159 |
+
return generate_answer(question)
|
| 160 |
|
| 161 |
|
| 162 |
recommender = SemanticSearch()
|
| 163 |
|
| 164 |
title = 'CauseWriter PDF'
|
| 165 |
+
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."""
|
| 166 |
|
| 167 |
|
| 168 |
with gr.Blocks() as demo:
|
|
|
|
| 173 |
with gr.Row():
|
| 174 |
|
| 175 |
with gr.Group():
|
|
|
|
|
|
|
| 176 |
url = gr.Textbox(label='Enter PDF URL here')
|
| 177 |
gr.Markdown("<center><h4>OR<h4></center>")
|
| 178 |
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
|
|
|
| 183 |
with gr.Group():
|
| 184 |
answer = gr.Textbox(label='The answer to your question is :')
|
| 185 |
|
| 186 |
+
btn.click(question_answer, inputs=[url, file, question], outputs=[answer])
|
|
|
|
|
|
|
| 187 |
|
| 188 |
+
demo.launch()
|