Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -91,7 +91,6 @@ class SemanticSearch:
|
|
91 |
return embeddings
|
92 |
|
93 |
|
94 |
-
openai.api_key = "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"
|
95 |
recommender = SemanticSearch()
|
96 |
|
97 |
def load_recommender(path, start_page=1):
|
@@ -136,7 +135,9 @@ def generate_answer(question):
|
|
136 |
return answer
|
137 |
|
138 |
|
139 |
-
def question_answer(url, file, question):
|
|
|
|
|
140 |
if url.strip() == '' and file == None:
|
141 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
142 |
|
@@ -168,6 +169,7 @@ with gr.Blocks() as demo:
|
|
168 |
|
169 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
170 |
gr.Markdown(description)
|
|
|
171 |
|
172 |
with gr.Row():
|
173 |
|
@@ -176,12 +178,13 @@ with gr.Blocks() as demo:
|
|
176 |
gr.Markdown("<center><h6>or<h6></center>")
|
177 |
file = gr.File(label='PDF', file_types=['.pdf'])
|
178 |
question = gr.Textbox(label='question')
|
|
|
179 |
btn = gr.Button(value='Submit')
|
180 |
btn.style(full_width=True)
|
181 |
|
182 |
with gr.Group():
|
183 |
answer = gr.Textbox(label='answer')
|
184 |
|
185 |
-
btn.click(question_answer, inputs=[url, file, question], outputs=[answer])
|
186 |
|
187 |
demo.launch()
|
|
|
91 |
return embeddings
|
92 |
|
93 |
|
|
|
94 |
recommender = SemanticSearch()
|
95 |
|
96 |
def load_recommender(path, start_page=1):
|
|
|
135 |
return answer
|
136 |
|
137 |
|
138 |
+
def question_answer(url, file, question, api_key):
|
139 |
+
openai.api_key = api_key
|
140 |
+
|
141 |
if url.strip() == '' and file == None:
|
142 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
143 |
|
|
|
169 |
|
170 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
171 |
gr.Markdown(description)
|
172 |
+
gr.Markdown('Thank you for all the support this space has received! Unfortunately, my OpenAI $18 grant has been exhausted, so you'll need to enter your own OpenAI API Key to use the app. But don't worry, I'll reimburse the money soon.')
|
173 |
|
174 |
with gr.Row():
|
175 |
|
|
|
178 |
gr.Markdown("<center><h6>or<h6></center>")
|
179 |
file = gr.File(label='PDF', file_types=['.pdf'])
|
180 |
question = gr.Textbox(label='question')
|
181 |
+
api_key = gr.Textbox(label='OpenAI API Key')
|
182 |
btn = gr.Button(value='Submit')
|
183 |
btn.style(full_width=True)
|
184 |
|
185 |
with gr.Group():
|
186 |
answer = gr.Textbox(label='answer')
|
187 |
|
188 |
+
btn.click(question_answer, inputs=[url, file, question, api_key], outputs=[answer])
|
189 |
|
190 |
demo.launch()
|