Spaces:
Runtime error
Runtime error
Upload app.py (#3)
Browse files- Upload app.py (f860dbdfd4917cbfd7f818f9dec3318405918289)
Co-authored-by: Disha Verma <dishav2@users.noreply.huggingface.co>
app.py
CHANGED
@@ -4,6 +4,8 @@ import os
|
|
4 |
import shutil
|
5 |
import time
|
6 |
import traceback
|
|
|
|
|
7 |
|
8 |
import gradio as gr
|
9 |
from dotenv import load_dotenv
|
@@ -106,13 +108,19 @@ def start_grading(history):
|
|
106 |
|
107 |
|
108 |
def start_downloading():
|
109 |
-
files = glob.glob("output/*.csv")
|
110 |
-
if files:
|
111 |
-
|
112 |
-
|
113 |
-
else:
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
def get_first_message(history):
|
118 |
global grader_qa
|
@@ -168,16 +176,28 @@ def enable_fields(url_status, canvas_api_key_status, submit_status, grade_status
|
|
168 |
canvas_api_key.placeholder = "Data already ingested"
|
169 |
|
170 |
|
171 |
-
def reset_data(
|
172 |
# Use shutil.rmtree() to delete output, docs, and vector_stores folders, reset grader and grader_qa, and get_grading_status, reset and return history
|
173 |
global grader, grader_qa
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
|
183 |
def get_output_dir(orig_name):
|
@@ -207,6 +227,10 @@ def upload_grading_results(file, history):
|
|
207 |
def bot(history):
|
208 |
return history
|
209 |
|
|
|
|
|
|
|
|
|
210 |
|
211 |
with gr.Blocks() as demo:
|
212 |
gr.Markdown(f"<h2><center>{'Canvas Discussion Grading With Feedback'}</center></h2>")
|
@@ -222,10 +246,16 @@ with gr.Blocks() as demo:
|
|
222 |
placeholder="Enter your Canvas API Key", type="password"
|
223 |
)
|
224 |
|
225 |
-
with gr.Row():
|
226 |
submit = gr.Button(value="Submit", variant="secondary", )
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
grade = gr.Button(value="Grade", variant="secondary")
|
228 |
download = gr.Button(value="Download", variant="secondary")
|
|
|
229 |
reset = gr.Button(value="Reset", variant="secondary")
|
230 |
|
231 |
chatbot = gr.Chatbot([], label="Chat with grading results", elem_id="chatbot", height=400)
|
@@ -240,6 +270,10 @@ with gr.Blocks() as demo:
|
|
240 |
ask = gr.Button(value="Ask", variant="secondary", scale=1)
|
241 |
|
242 |
chatbot.value = get_first_message([])
|
|
|
|
|
|
|
|
|
243 |
submit.click(ingest, inputs=[url, canvas_api_key, chatbot], outputs=[chatbot, url, canvas_api_key, submit, grade],
|
244 |
postprocess=False).then(
|
245 |
bot, chatbot, chatbot
|
@@ -250,7 +284,7 @@ with gr.Blocks() as demo:
|
|
250 |
bot, chatbot, chatbot
|
251 |
)
|
252 |
|
253 |
-
download.click(start_downloading, inputs=[], outputs=[
|
254 |
bot, chatbot, chatbot
|
255 |
)
|
256 |
|
@@ -262,7 +296,7 @@ with gr.Blocks() as demo:
|
|
262 |
bot, chatbot, chatbot
|
263 |
)
|
264 |
|
265 |
-
reset.click(reset_data, inputs=[
|
266 |
bot, chatbot, chatbot)
|
267 |
|
268 |
upload.upload(upload_grading_results, inputs=[upload, chatbot], outputs=[chatbot], postprocess=False, ).then(
|
|
|
4 |
import shutil
|
5 |
import time
|
6 |
import traceback
|
7 |
+
import pandas as pd
|
8 |
+
import utils
|
9 |
|
10 |
import gradio as gr
|
11 |
from dotenv import load_dotenv
|
|
|
108 |
|
109 |
|
110 |
def start_downloading():
|
111 |
+
# files = glob.glob("output/*.csv")
|
112 |
+
# if files:
|
113 |
+
# file = files[0]
|
114 |
+
# return gr.outputs.File(file)
|
115 |
+
# else:
|
116 |
+
# return "File not found"
|
117 |
+
print(grader.csv)
|
118 |
+
return grader.csv, gr.update(visible=True), gr.update(value=process_csv_text(), visible=True)
|
119 |
+
|
120 |
+
def get_headers():
|
121 |
+
df = process_csv_text()
|
122 |
+
return list(df.columns)
|
123 |
+
|
124 |
|
125 |
def get_first_message(history):
|
126 |
global grader_qa
|
|
|
176 |
canvas_api_key.placeholder = "Data already ingested"
|
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')
|
186 |
+
reset_folder('docs')
|
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):
|
|
|
227 |
def bot(history):
|
228 |
return history
|
229 |
|
230 |
+
def process_csv_text():
|
231 |
+
file_path = utils.get_csv_file_name()
|
232 |
+
df = pd.read_csv(file_path)
|
233 |
+
return df
|
234 |
|
235 |
with gr.Blocks() as demo:
|
236 |
gr.Markdown(f"<h2><center>{'Canvas Discussion Grading With Feedback'}</center></h2>")
|
|
|
246 |
placeholder="Enter your Canvas API Key", type="password"
|
247 |
)
|
248 |
|
|
|
249 |
submit = gr.Button(value="Submit", variant="secondary", )
|
250 |
+
with gr.Row():
|
251 |
+
table = gr.Dataframe(label ='Canvas CSV Output', type="pandas", overflow_row_behaviour="paginate", visible = False, wrap=True)
|
252 |
+
|
253 |
+
|
254 |
+
with gr.Row():
|
255 |
+
|
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.Button(value="Reset", variant="secondary")
|
260 |
|
261 |
chatbot = gr.Chatbot([], label="Chat with grading results", elem_id="chatbot", height=400)
|
|
|
270 |
ask = gr.Button(value="Ask", variant="secondary", scale=1)
|
271 |
|
272 |
chatbot.value = get_first_message([])
|
273 |
+
|
274 |
+
with gr.Row():
|
275 |
+
table = gr.Dataframe(label ='Canvas CSV Output', type="pandas", overflow_row_behaviour="paginate", visible = False, wrap=True)
|
276 |
+
|
277 |
submit.click(ingest, inputs=[url, canvas_api_key, chatbot], outputs=[chatbot, url, canvas_api_key, submit, grade],
|
278 |
postprocess=False).then(
|
279 |
bot, chatbot, chatbot
|
|
|
284 |
bot, chatbot, chatbot
|
285 |
)
|
286 |
|
287 |
+
download.click(start_downloading, inputs=[], outputs=[file, file, table]).then(
|
288 |
bot, chatbot, chatbot
|
289 |
)
|
290 |
|
|
|
296 |
bot, chatbot, chatbot
|
297 |
)
|
298 |
|
299 |
+
reset.click(reset_data, inputs=[], outputs=[], postprocess=False, show_progress=True, ).success(
|
300 |
bot, chatbot, chatbot)
|
301 |
|
302 |
upload.upload(upload_grading_results, inputs=[upload, chatbot], outputs=[chatbot], postprocess=False, ).then(
|