Spaces:
Runtime error
Runtime error
Added Reset Functionality
#5
by
dishav2
- opened
app.py
CHANGED
|
@@ -177,9 +177,10 @@ def enable_fields(url_status, canvas_api_key_status, submit_status, grade_status
|
|
| 177 |
|
| 178 |
|
| 179 |
def reset_data():
|
|
|
|
| 180 |
# Use shutil.rmtree() to delete output, docs, and vector_stores folders, reset grader and grader_qa, and get_grading_status, reset and return history
|
| 181 |
global grader, grader_qa
|
| 182 |
-
#If there's data in docs/output folder during grading
|
| 183 |
if os.path.isdir('output') and len(glob.glob("output/*.csv")) > 0 and len(glob.glob("docs/*.json")) > 0 and len(
|
| 184 |
glob.glob("docs/*.html")) > 0:
|
| 185 |
reset_folder('output')
|
|
@@ -187,17 +188,17 @@ def reset_data():
|
|
| 187 |
grader = None
|
| 188 |
grader_qa = None
|
| 189 |
history = [(None, 'Data reset successfully')]
|
| 190 |
-
return history
|
| 191 |
-
# If there's data in docs folder
|
| 192 |
elif len(glob.glob("docs/*.json")) > 0 and len(glob.glob("docs/*.html")):
|
| 193 |
reset_folder('docs')
|
| 194 |
history = [(None, 'Data reset successfully')]
|
| 195 |
-
return history
|
| 196 |
#If there's data in vector_stores folder
|
| 197 |
elif len(glob.glob("vector_stores/*.faiss")) > 0 or len(glob.glob("vector_stores/*.pkl")) > 0:
|
| 198 |
reset_folder('vector_stores')
|
| 199 |
history = [(None, 'Data reset successfully')]
|
| 200 |
-
return history
|
| 201 |
|
| 202 |
|
| 203 |
def get_output_dir(orig_name):
|
|
@@ -256,7 +257,7 @@ with gr.Blocks() as demo:
|
|
| 256 |
grade = gr.Button(value="Grade", variant="secondary")
|
| 257 |
download = gr.Button(value="Download", variant="secondary")
|
| 258 |
file = gr.components.File(label="CSV Output", container=False, visible=False).style(height=100)
|
| 259 |
-
reset = gr.
|
| 260 |
|
| 261 |
chatbot = gr.Chatbot([], label="Chat with grading results", elem_id="chatbot", height=400)
|
| 262 |
|
|
@@ -296,7 +297,7 @@ with gr.Blocks() as demo:
|
|
| 296 |
bot, chatbot, chatbot
|
| 297 |
)
|
| 298 |
|
| 299 |
-
reset.click(reset_data, inputs=[], outputs=[
|
| 300 |
bot, chatbot, chatbot)
|
| 301 |
|
| 302 |
upload.upload(upload_grading_results, inputs=[upload, chatbot], outputs=[chatbot], postprocess=False, ).then(
|
|
|
|
| 177 |
|
| 178 |
|
| 179 |
def reset_data():
|
| 180 |
+
def reset_data():
|
| 181 |
# Use shutil.rmtree() to delete output, docs, and vector_stores folders, reset grader and grader_qa, and get_grading_status, reset and return history
|
| 182 |
global grader, grader_qa
|
| 183 |
+
#If there's data in docs/output folder during grading [During Grading]
|
| 184 |
if os.path.isdir('output') and len(glob.glob("output/*.csv")) > 0 and len(glob.glob("docs/*.json")) > 0 and len(
|
| 185 |
glob.glob("docs/*.html")) > 0:
|
| 186 |
reset_folder('output')
|
|
|
|
| 188 |
grader = None
|
| 189 |
grader_qa = None
|
| 190 |
history = [(None, 'Data reset successfully')]
|
| 191 |
+
return history, disabled, disabled, disabled, enabled, enabled, enabled
|
| 192 |
+
# If there's data in docs folder [During Ingestion]
|
| 193 |
elif len(glob.glob("docs/*.json")) > 0 and len(glob.glob("docs/*.html")):
|
| 194 |
reset_folder('docs')
|
| 195 |
history = [(None, 'Data reset successfully')]
|
| 196 |
+
return history, enabled, enabled, enabled, disabled, disabled, disabled
|
| 197 |
#If there's data in vector_stores folder
|
| 198 |
elif len(glob.glob("vector_stores/*.faiss")) > 0 or len(glob.glob("vector_stores/*.pkl")) > 0:
|
| 199 |
reset_folder('vector_stores')
|
| 200 |
history = [(None, 'Data reset successfully')]
|
| 201 |
+
return history, disabled, disabled, disabled, enabled, disabled, enabled
|
| 202 |
|
| 203 |
|
| 204 |
def get_output_dir(orig_name):
|
|
|
|
| 257 |
grade = gr.Button(value="Grade", variant="secondary")
|
| 258 |
download = gr.Button(value="Download", variant="secondary")
|
| 259 |
file = gr.components.File(label="CSV Output", container=False, visible=False).style(height=100)
|
| 260 |
+
reset = gr.ClearButton(value="Reset")
|
| 261 |
|
| 262 |
chatbot = gr.Chatbot([], label="Chat with grading results", elem_id="chatbot", height=400)
|
| 263 |
|
|
|
|
| 297 |
bot, chatbot, chatbot
|
| 298 |
)
|
| 299 |
|
| 300 |
+
reset.click(reset_data, inputs=[], outputs=[chatbot, url, canvas_api_key, submit, table, grade, download]).success(
|
| 301 |
bot, chatbot, chatbot)
|
| 302 |
|
| 303 |
upload.upload(upload_grading_results, inputs=[upload, chatbot], outputs=[chatbot], postprocess=False, ).then(
|