Spaces:
Running
Running
Commit
·
2390eff
1
Parent(s):
c1dcb26
Update app.py
Browse files
app.py
CHANGED
@@ -99,7 +99,8 @@ def load_recommender(path, start_page=1):
|
|
99 |
return 'Corpus Loaded.'
|
100 |
|
101 |
|
102 |
-
def generate_text(prompt, engine="text-davinci-003"):
|
|
|
103 |
completions = openai.Completion.create(
|
104 |
engine=engine,
|
105 |
prompt=prompt,
|
@@ -112,7 +113,7 @@ def generate_text(prompt, engine="text-davinci-003"):
|
|
112 |
return message
|
113 |
|
114 |
|
115 |
-
def generate_answer(question):
|
116 |
topn_chunks = recommender(question)
|
117 |
prompt = ""
|
118 |
prompt += 'search results:\n\n'
|
@@ -129,11 +130,11 @@ def generate_answer(question):
|
|
129 |
"answer should be short and concise.\n\nQuery: {question}\nAnswer: "
|
130 |
|
131 |
prompt += f"Query: {question}\nAnswer:"
|
132 |
-
answer = generate_text(prompt)
|
133 |
return answer
|
134 |
|
135 |
|
136 |
-
def question_answer(url, file, question):
|
137 |
if url.strip() == '' and file == None:
|
138 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
139 |
|
@@ -155,7 +156,7 @@ def question_answer(url, file, question):
|
|
155 |
if question.strip() == '':
|
156 |
return '[ERROR]: Question field is empty'
|
157 |
|
158 |
-
return generate_answer(question)
|
159 |
|
160 |
|
161 |
recommender = SemanticSearch()
|
@@ -175,6 +176,7 @@ with gr.Blocks() as demo:
|
|
175 |
with gr.Row():
|
176 |
|
177 |
with gr.Group():
|
|
|
178 |
url = gr.Textbox(label='Enter PDF URL here')
|
179 |
gr.Markdown("<center><h4>OR<h4></center>")
|
180 |
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
@@ -185,7 +187,7 @@ with gr.Blocks() as demo:
|
|
185 |
with gr.Group():
|
186 |
answer = gr.Textbox(label='The answer to your question is :')
|
187 |
|
188 |
-
btn.click(question_answer, inputs=[url, file, question], outputs=[answer])
|
189 |
openai.api_key = os.getenv('Your_Key_Here')
|
190 |
demo.launch()
|
191 |
|
|
|
99 |
return 'Corpus Loaded.'
|
100 |
|
101 |
|
102 |
+
def generate_text(prompt, engine="text-davinci-003",openAI_key):
|
103 |
+
openai.api_key = openAI_key
|
104 |
completions = openai.Completion.create(
|
105 |
engine=engine,
|
106 |
prompt=prompt,
|
|
|
113 |
return message
|
114 |
|
115 |
|
116 |
+
def generate_answer(question,openAI_key):
|
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,openAI_key)
|
134 |
return answer
|
135 |
|
136 |
|
137 |
+
def question_answer(url, file, question,openAI_key):
|
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,openAI_key)
|
160 |
|
161 |
|
162 |
recommender = SemanticSearch()
|
|
|
176 |
with gr.Row():
|
177 |
|
178 |
with gr.Group():
|
179 |
+
api_key=gr.Textbox(label='Enter your OpenAI API 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 |
with gr.Group():
|
188 |
answer = gr.Textbox(label='The answer to your question is :')
|
189 |
|
190 |
+
btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
191 |
openai.api_key = os.getenv('Your_Key_Here')
|
192 |
demo.launch()
|
193 |
|