Spaces:
Runtime error
Runtime error
Changes to UI
Browse files
app.py
CHANGED
@@ -135,7 +135,7 @@ def generate_answer(question):
|
|
135 |
return answer
|
136 |
|
137 |
|
138 |
-
def
|
139 |
if url.strip() == '' and file == None:
|
140 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
141 |
|
@@ -153,16 +153,9 @@ def load_corpus(url, file):
|
|
153 |
file_name = file_name[:-12] + file_name[-4:]
|
154 |
os.rename(old_file_name, file_name)
|
155 |
load_recommender(file_name)
|
156 |
-
|
157 |
-
return 'Corpus Loaded. Now you can ask Questions.'
|
158 |
-
|
159 |
|
160 |
-
def question_answer(question):
|
161 |
if question.strip() == '':
|
162 |
return '[ERROR]: Question field is empty'
|
163 |
-
|
164 |
-
if not recommender.fitted:
|
165 |
-
return '[ERROR]: First, provide a URL or Upload a PDF and hit submit (see left panel)'
|
166 |
|
167 |
return generate_answer(question)
|
168 |
|
@@ -174,28 +167,20 @@ with gr.Blocks() as demo:
|
|
174 |
|
175 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
176 |
gr.Markdown(description)
|
177 |
-
gr.Markdown('<br>')
|
178 |
|
179 |
with gr.Row():
|
180 |
|
181 |
with gr.Group():
|
182 |
-
gr.Markdown('### Step 1: Provide URL or Upload PDF')
|
183 |
-
gr.Markdown('<br>')
|
184 |
url = gr.Textbox(label='URL')
|
185 |
-
gr.Markdown("<center><
|
186 |
file = gr.File(label='PDF', file_types=['.pdf'])
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
btn1.click(load_corpus, inputs=[url, file], outputs=[stataus])
|
191 |
|
192 |
with gr.Group():
|
193 |
-
gr.Markdown('### Step 2: Now you can ask Questions:')
|
194 |
-
gr.Markdown('<br>')
|
195 |
-
question = gr.Textbox(label='question')
|
196 |
-
btn2 = gr.Button(value='Submit')
|
197 |
-
btn2.style(full_width=True)
|
198 |
answer = gr.Textbox(label='answer')
|
199 |
-
|
|
|
200 |
|
201 |
demo.launch()
|
|
|
135 |
return answer
|
136 |
|
137 |
|
138 |
+
def question_answer(url, file, question):
|
139 |
if url.strip() == '' and file == None:
|
140 |
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
141 |
|
|
|
153 |
file_name = file_name[:-12] + file_name[-4:]
|
154 |
os.rename(old_file_name, file_name)
|
155 |
load_recommender(file_name)
|
|
|
|
|
|
|
156 |
|
|
|
157 |
if question.strip() == '':
|
158 |
return '[ERROR]: Question field is empty'
|
|
|
|
|
|
|
159 |
|
160 |
return generate_answer(question)
|
161 |
|
|
|
167 |
|
168 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
169 |
gr.Markdown(description)
|
|
|
170 |
|
171 |
with gr.Row():
|
172 |
|
173 |
with gr.Group():
|
|
|
|
|
174 |
url = gr.Textbox(label='URL')
|
175 |
+
gr.Markdown("<center><h6>or<h6></center>")
|
176 |
file = gr.File(label='PDF', file_types=['.pdf'])
|
177 |
+
question = gr.Textbox(label='question')
|
178 |
+
btn = gr.Button(value='Submit')
|
179 |
+
btn.style(full_width=True)
|
|
|
180 |
|
181 |
with gr.Group():
|
|
|
|
|
|
|
|
|
|
|
182 |
answer = gr.Textbox(label='answer')
|
183 |
+
|
184 |
+
btn.click(question_answer, inputs=[url, file, question], outputs=[answer])
|
185 |
|
186 |
demo.launch()
|