Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -134,27 +134,14 @@ def generate_answer(question,openAI_key):
|
|
134 |
return answer
|
135 |
|
136 |
|
137 |
-
def question_answer(url,
|
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 |
-
|
143 |
-
if url.strip() != '' and file != None:
|
144 |
-
return '[ERROR]: Both URL and PDF is provided. Please provide only one (eiter URL or PDF).'
|
145 |
-
|
146 |
if url.strip() != '':
|
147 |
glob_url = url
|
148 |
download_pdf(glob_url, 'corpus.pdf')
|
149 |
load_recommender('corpus.pdf')
|
150 |
|
151 |
-
else:
|
152 |
-
old_file_name = file.name
|
153 |
-
file_name = file.name
|
154 |
-
file_name = file_name[:-12] + file_name[-4:]
|
155 |
-
os.rename(old_file_name, file_name)
|
156 |
-
load_recommender(file_name)
|
157 |
-
|
158 |
if question.strip() == '':
|
159 |
return '[ERROR]: Question field is empty'
|
160 |
|
@@ -180,7 +167,6 @@ with gr.Blocks() as demo:
|
|
180 |
openAI_key=gr.Textbox(label='Enter your OpenAI API key here')
|
181 |
url = gr.Textbox(label='Enter PDF URL here')
|
182 |
gr.Markdown("<center><h4>OR<h4></center>")
|
183 |
-
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
184 |
question = gr.Textbox(label='Enter your question here')
|
185 |
btn = gr.Button(value='Submit')
|
186 |
btn.style(full_width=True)
|
@@ -188,7 +174,7 @@ with gr.Blocks() as demo:
|
|
188 |
with gr.Group():
|
189 |
answer = gr.Textbox(label='The answer to your question is :')
|
190 |
|
191 |
-
btn.click(question_answer, inputs=[url,
|
192 |
#openai.api_key = os.getenv('Your_Key_Here')
|
193 |
demo.launch()
|
194 |
|
|
|
134 |
return answer
|
135 |
|
136 |
|
137 |
+
def question_answer(url, question,openAI_key):
|
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() != '':
|
141 |
glob_url = url
|
142 |
download_pdf(glob_url, 'corpus.pdf')
|
143 |
load_recommender('corpus.pdf')
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
if question.strip() == '':
|
146 |
return '[ERROR]: Question field is empty'
|
147 |
|
|
|
167 |
openAI_key=gr.Textbox(label='Enter your OpenAI API key here')
|
168 |
url = gr.Textbox(label='Enter PDF URL here')
|
169 |
gr.Markdown("<center><h4>OR<h4></center>")
|
|
|
170 |
question = gr.Textbox(label='Enter your question here')
|
171 |
btn = gr.Button(value='Submit')
|
172 |
btn.style(full_width=True)
|
|
|
174 |
with gr.Group():
|
175 |
answer = gr.Textbox(label='The answer to your question is :')
|
176 |
|
177 |
+
btn.click(question_answer, inputs=[url, question,openAI_key], outputs=[answer], api_name="ask")
|
178 |
#openai.api_key = os.getenv('Your_Key_Here')
|
179 |
demo.launch()
|
180 |
|