Spaces:
Runtime error
Runtime error
Merge remote-tracking branch 'origin/main'
Browse files
app.py
CHANGED
@@ -4,14 +4,15 @@ import os
|
|
4 |
import shutil
|
5 |
import time
|
6 |
import traceback
|
|
|
|
|
7 |
|
|
|
8 |
import gradio as gr
|
9 |
-
import pandas as pd
|
10 |
from dotenv import load_dotenv
|
11 |
from langchain.chat_models import ChatOpenAI
|
12 |
from langchain.embeddings import OpenAIEmbeddings
|
13 |
|
14 |
-
import utils
|
15 |
from csv_agent import CSVAgent
|
16 |
from grader import Grader
|
17 |
from grader_qa import GraderQA
|
@@ -107,13 +108,21 @@ def start_grading(history):
|
|
107 |
return history, disabled, enabled, enabled, enabled
|
108 |
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
def start_downloading():
|
111 |
-
#
|
112 |
-
#
|
113 |
-
#
|
114 |
-
#
|
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 |
|
@@ -122,6 +131,8 @@ def get_headers():
|
|
122 |
return list(df.columns)
|
123 |
|
124 |
|
|
|
|
|
125 |
def get_first_message(history):
|
126 |
global grader_qa
|
127 |
history = [(None,
|
@@ -179,27 +190,27 @@ def enable_fields(url_status, canvas_api_key_status, submit_status, grade_status
|
|
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 [During Grading]
|
183 |
-
if os.path.isdir('output') and len(glob.glob("output/*.csv")) > 0
|
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 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
history = [(None, 'Data reset successfully')]
|
195 |
-
return history, enabled, enabled, enabled, disabled, disabled, disabled
|
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, enabled, enabled, enabled, disabled, disabled, disabled
|
201 |
-
|
202 |
-
|
203 |
def get_output_dir(orig_name):
|
204 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
205 |
output_dir = os.path.join(script_dir, 'output', orig_name)
|
@@ -227,13 +238,16 @@ def upload_grading_results(file, history):
|
|
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>")
|
|
|
237 |
|
238 |
with gr.Row():
|
239 |
url = gr.Textbox(
|
@@ -245,33 +259,34 @@ with gr.Blocks() as demo:
|
|
245 |
label="Canvas API Key",
|
246 |
placeholder="Enter your Canvas API Key", type="password"
|
247 |
)
|
248 |
-
|
249 |
-
submit = gr.Button(value="Step 1: 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 |
-
with gr.Row():
|
254 |
-
|
255 |
-
|
|
|
256 |
file = gr.components.File(label="CSV Output", container=False, visible=False).style(height=100)
|
|
|
257 |
reset = gr.ClearButton(value="Reset")
|
258 |
|
259 |
chatbot = gr.Chatbot([], label="Chat with grading results", elem_id="chatbot", height=400)
|
260 |
-
|
261 |
with gr.Row():
|
262 |
with gr.Column(scale=3):
|
263 |
txt = gr.Textbox(
|
264 |
label="Ask questions about how students did on the discussion",
|
265 |
placeholder="Enter text and press enter, or upload an image", lines=1
|
266 |
)
|
267 |
-
|
268 |
-
upload = gr.UploadButton(label="Upload grading results", type="file", file_types=["csv"], scale=
|
269 |
-
|
270 |
chatbot.value = get_first_message([])
|
271 |
|
272 |
with gr.Row():
|
273 |
table = gr.Dataframe(label ='Canvas CSV Output', type="pandas", overflow_row_behaviour="paginate", visible = False, wrap=True)
|
274 |
-
|
275 |
submit.click(ingest, inputs=[url, canvas_api_key, chatbot], outputs=[chatbot, url, canvas_api_key, submit, grade],
|
276 |
postprocess=False).then(
|
277 |
bot, chatbot, chatbot
|
@@ -285,7 +300,8 @@ with gr.Blocks() as demo:
|
|
285 |
download.click(start_downloading, inputs=[], outputs=[file, file, table]).then(
|
286 |
bot, chatbot, chatbot
|
287 |
)
|
288 |
-
|
|
|
289 |
txt.submit(add_text, [chatbot, txt], [chatbot, txt], postprocess=False).then(
|
290 |
bot, chatbot, chatbot
|
291 |
)
|
@@ -294,7 +310,7 @@ with gr.Blocks() as demo:
|
|
294 |
bot, chatbot, chatbot
|
295 |
)
|
296 |
|
297 |
-
reset.click(reset_data, inputs=[], outputs=[chatbot, url, canvas_api_key, submit, table, grade, download]).success(
|
298 |
bot, chatbot, chatbot)
|
299 |
|
300 |
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 |
+
from zipfile import ZipFile
|
11 |
import gradio as gr
|
|
|
12 |
from dotenv import load_dotenv
|
13 |
from langchain.chat_models import ChatOpenAI
|
14 |
from langchain.embeddings import OpenAIEmbeddings
|
15 |
|
|
|
16 |
from csv_agent import CSVAgent
|
17 |
from grader import Grader
|
18 |
from grader_qa import GraderQA
|
|
|
108 |
return history, disabled, enabled, enabled, enabled
|
109 |
|
110 |
|
111 |
+
# def start_downloading(history):
|
112 |
+
# files = glob.glob("output/*.csv")
|
113 |
+
# if files:
|
114 |
+
# file = files[0]
|
115 |
+
# download.interactive = True
|
116 |
+
# return gr.components.File(file)
|
117 |
+
# else:
|
118 |
+
# return " No file found"
|
119 |
+
|
120 |
+
|
121 |
def start_downloading():
|
122 |
+
# with ZipFile("output/*.csv", "w") as zipObj:
|
123 |
+
# for idx, file in enumerate(files):
|
124 |
+
# zipObj.write(file.name, file.name.split("/")[-1])
|
125 |
+
# return "outputfiles.zip"
|
|
|
|
|
126 |
print(grader.csv)
|
127 |
return grader.csv, gr.update(visible=True), gr.update(value=process_csv_text(), visible=True)
|
128 |
|
|
|
131 |
return list(df.columns)
|
132 |
|
133 |
|
134 |
+
#file_input = glob.glob("output/*.csv") #[gr.File(file_count="multiple", file_types=["text", ".json", ".csv"])]
|
135 |
+
|
136 |
def get_first_message(history):
|
137 |
global grader_qa
|
138 |
history = [(None,
|
|
|
190 |
def reset_data():
|
191 |
# Use shutil.rmtree() to delete output, docs, and vector_stores folders, reset grader and grader_qa, and get_grading_status, reset and return history
|
192 |
global grader, grader_qa
|
193 |
+
# reset_folder('output')
|
194 |
+
# reset_folder('docs')
|
195 |
+
# reset_folder('vector_stores')
|
196 |
+
# grader = None
|
197 |
+
# grader_qa = None
|
198 |
+
# history = [(None, 'Data reset successfully')]
|
199 |
+
# return history
|
200 |
+
#disha
|
201 |
#If there's data in docs/output folder during grading [During Grading]
|
202 |
+
if os.path.isdir('output') and len(glob.glob("output/*.csv")) > 0 or len(glob.glob("docs/*.json")) > 0 or len(
|
203 |
+
glob.glob("docs/*.html")) > 0 or len(glob.glob("vector_stores/*.faiss")) > 0 or len(glob.glob("vector_stores/*.pkl")) > 0:
|
204 |
reset_folder('output')
|
205 |
reset_folder('docs')
|
206 |
+
reset_folder('vector_stores')
|
207 |
grader = None
|
208 |
grader_qa = None
|
209 |
history = [(None, 'Data reset successfully')]
|
210 |
+
url.placeholder = [(None, 'Enter your Canvas Discussion URL')]
|
211 |
+
canvas_api_key.placeholder = [(None, 'Enter your Canvas API Key')]
|
212 |
+
return history, enabled, enabled, enabled, disabled, disabled, disabled, disabled, disabled, disabled, disabled, disabled
|
213 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
def get_output_dir(orig_name):
|
215 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
216 |
output_dir = os.path.join(script_dir, 'output', orig_name)
|
|
|
238 |
def bot(history):
|
239 |
return history
|
240 |
|
241 |
+
|
242 |
def process_csv_text():
|
243 |
file_path = utils.get_csv_file_name()
|
244 |
df = pd.read_csv(file_path)
|
245 |
return df
|
246 |
|
247 |
+
|
248 |
with gr.Blocks() as demo:
|
249 |
gr.Markdown(f"<h2><center>{'Canvas Discussion Grading With Feedback'}</center></h2>")
|
250 |
+
|
251 |
|
252 |
with gr.Row():
|
253 |
url = gr.Textbox(
|
|
|
259 |
label="Canvas API Key",
|
260 |
placeholder="Enter your Canvas API Key", type="password"
|
261 |
)
|
262 |
+
submit = gr.Button(value="Submit", variant="secondary", )
|
|
|
263 |
with gr.Row():
|
264 |
table = gr.Dataframe(label ='Canvas CSV Output', type="pandas", overflow_row_behaviour="paginate", visible = False, wrap=True)
|
265 |
|
266 |
+
with gr.Row(equal_height=True):
|
267 |
+
|
268 |
+
grade = gr.Button(value="Grade", variant="secondary")
|
269 |
+
download = gr.Button(value="Generate Output", variant="secondary")
|
270 |
file = gr.components.File(label="CSV Output", container=False, visible=False).style(height=100)
|
271 |
+
#reset = gr.ClearButton(value="Reset", components=[url, canvas_api_key, submit, table, grade, download])
|
272 |
reset = gr.ClearButton(value="Reset")
|
273 |
|
274 |
chatbot = gr.Chatbot([], label="Chat with grading results", elem_id="chatbot", height=400)
|
275 |
+
|
276 |
with gr.Row():
|
277 |
with gr.Column(scale=3):
|
278 |
txt = gr.Textbox(
|
279 |
label="Ask questions about how students did on the discussion",
|
280 |
placeholder="Enter text and press enter, or upload an image", lines=1
|
281 |
)
|
282 |
+
|
283 |
+
upload = gr.UploadButton(label="Upload grading results", type="file", file_types=["csv"], scale=1)
|
284 |
+
ask = gr.Button(value="Ask", variant="secondary", scale=1)
|
285 |
chatbot.value = get_first_message([])
|
286 |
|
287 |
with gr.Row():
|
288 |
table = gr.Dataframe(label ='Canvas CSV Output', type="pandas", overflow_row_behaviour="paginate", visible = False, wrap=True)
|
289 |
+
|
290 |
submit.click(ingest, inputs=[url, canvas_api_key, chatbot], outputs=[chatbot, url, canvas_api_key, submit, grade],
|
291 |
postprocess=False).then(
|
292 |
bot, chatbot, chatbot
|
|
|
300 |
download.click(start_downloading, inputs=[], outputs=[file, file, table]).then(
|
301 |
bot, chatbot, chatbot
|
302 |
)
|
303 |
+
|
304 |
+
|
305 |
txt.submit(add_text, [chatbot, txt], [chatbot, txt], postprocess=False).then(
|
306 |
bot, chatbot, chatbot
|
307 |
)
|
|
|
310 |
bot, chatbot, chatbot
|
311 |
)
|
312 |
|
313 |
+
reset.click(reset_data, inputs=[], outputs=[chatbot, url, canvas_api_key, submit, table, grade, download, txt, file, upload, ask]).success(
|
314 |
bot, chatbot, chatbot)
|
315 |
|
316 |
upload.upload(upload_grading_results, inputs=[upload, chatbot], outputs=[chatbot], postprocess=False, ).then(
|