Spaces:
Runtime error
Runtime error
Startup and workflow UI validations
Browse files
app.py
CHANGED
@@ -29,6 +29,8 @@ embeddings = OpenAIEmbeddings(model='text-embedding-ada-002')
|
|
29 |
|
30 |
grader = None
|
31 |
grader_qa = None
|
|
|
|
|
32 |
|
33 |
|
34 |
def add_text(history, text):
|
@@ -77,7 +79,7 @@ def ingest(url, canvas_api_key, history):
|
|
77 |
grader = Grader(grading_model)
|
78 |
response = "Ingested canvas data successfully"
|
79 |
history = history + [(text, response)]
|
80 |
-
return history
|
81 |
|
82 |
|
83 |
def start_grading(history):
|
@@ -100,7 +102,7 @@ def start_grading(history):
|
|
100 |
else:
|
101 |
response = "Please ingest data before grading"
|
102 |
history = history + [(text, response)]
|
103 |
-
return history
|
104 |
|
105 |
|
106 |
def start_downloading():
|
@@ -131,40 +133,39 @@ def get_grading_status(history):
|
|
131 |
grader_qa = GraderQA(grader, embeddings)
|
132 |
if len(history) == 1:
|
133 |
history = history + [(None, 'Grading is already complete. You can now ask questions')]
|
134 |
-
|
135 |
# Check if data is ingested
|
136 |
elif len(glob.glob("docs/*.json")) > 0 and len(glob.glob("docs/*.html")):
|
137 |
if not grader_qa:
|
138 |
grader = Grader(qa_model)
|
139 |
if len(history) == 1:
|
140 |
history = history + [(None, 'Canvas data is already ingested. You can grade discussions now')]
|
141 |
-
|
142 |
else:
|
143 |
history = history + [(None, 'Please ingest data and start grading')]
|
144 |
-
|
145 |
return history
|
146 |
|
147 |
|
148 |
# handle enable/disable of fields
|
149 |
def enable_fields(url_status, canvas_api_key_status, submit_status, grade_status,
|
150 |
download_status, chatbot_txt_status, chatbot_btn_status):
|
151 |
-
url.
|
152 |
-
canvas_api_key.
|
153 |
-
submit.
|
154 |
-
grade.
|
155 |
-
download.
|
156 |
-
txt.
|
157 |
-
ask.
|
158 |
|
159 |
if not chatbot_txt_status:
|
160 |
-
txt.
|
161 |
else:
|
162 |
-
txt.
|
163 |
if not url_status:
|
164 |
-
url.
|
165 |
if not canvas_api_key_status:
|
166 |
-
canvas_api_key.
|
167 |
-
return url, canvas_api_key, submit, grade, download, txt, ask
|
168 |
|
169 |
|
170 |
def reset_data(history):
|
@@ -239,12 +240,12 @@ with gr.Blocks() as demo:
|
|
239 |
ask = gr.Button(value="Ask", variant="secondary", scale=1)
|
240 |
|
241 |
chatbot.value = get_first_message([])
|
242 |
-
submit.click(ingest, inputs=[url, canvas_api_key, chatbot], outputs=[chatbot],
|
243 |
postprocess=False).then(
|
244 |
bot, chatbot, chatbot
|
245 |
)
|
246 |
|
247 |
-
grade.click(start_grading, inputs=[chatbot], outputs=[chatbot],
|
248 |
postprocess=False).then(
|
249 |
bot, chatbot, chatbot
|
250 |
)
|
|
|
29 |
|
30 |
grader = None
|
31 |
grader_qa = None
|
32 |
+
disabled = gr.update(interactive=False)
|
33 |
+
enabled = gr.update(interactive=True)
|
34 |
|
35 |
|
36 |
def add_text(history, text):
|
|
|
79 |
grader = Grader(grading_model)
|
80 |
response = "Ingested canvas data successfully"
|
81 |
history = history + [(text, response)]
|
82 |
+
return history, disabled, disabled, disabled, enabled
|
83 |
|
84 |
|
85 |
def start_grading(history):
|
|
|
102 |
else:
|
103 |
response = "Please ingest data before grading"
|
104 |
history = history + [(text, response)]
|
105 |
+
return history, disabled, enabled, enabled, enabled
|
106 |
|
107 |
|
108 |
def start_downloading():
|
|
|
133 |
grader_qa = GraderQA(grader, embeddings)
|
134 |
if len(history) == 1:
|
135 |
history = history + [(None, 'Grading is already complete. You can now ask questions')]
|
136 |
+
enable_fields(False, False, False, False, True, True, True)
|
137 |
# Check if data is ingested
|
138 |
elif len(glob.glob("docs/*.json")) > 0 and len(glob.glob("docs/*.html")):
|
139 |
if not grader_qa:
|
140 |
grader = Grader(qa_model)
|
141 |
if len(history) == 1:
|
142 |
history = history + [(None, 'Canvas data is already ingested. You can grade discussions now')]
|
143 |
+
enable_fields(False, False, False, True, True, False, False)
|
144 |
else:
|
145 |
history = history + [(None, 'Please ingest data and start grading')]
|
146 |
+
enable_fields(True, True, True, False, False, False, False)
|
147 |
return history
|
148 |
|
149 |
|
150 |
# handle enable/disable of fields
|
151 |
def enable_fields(url_status, canvas_api_key_status, submit_status, grade_status,
|
152 |
download_status, chatbot_txt_status, chatbot_btn_status):
|
153 |
+
url.interactive = url_status
|
154 |
+
canvas_api_key.interactive = canvas_api_key_status
|
155 |
+
submit.interactive = submit_status
|
156 |
+
grade.interactive = grade_status
|
157 |
+
download.interactive = download_status
|
158 |
+
txt.interactive = chatbot_txt_status
|
159 |
+
ask.interactive = chatbot_btn_status
|
160 |
|
161 |
if not chatbot_txt_status:
|
162 |
+
txt.placeholder = "Please grade discussions first"
|
163 |
else:
|
164 |
+
txt.placeholder = "Ask a question"
|
165 |
if not url_status:
|
166 |
+
url.placeholder = "Data already ingested"
|
167 |
if not canvas_api_key_status:
|
168 |
+
canvas_api_key.placeholder = "Data already ingested"
|
|
|
169 |
|
170 |
|
171 |
def reset_data(history):
|
|
|
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
|
246 |
)
|
247 |
|
248 |
+
grade.click(start_grading, inputs=[chatbot], outputs=[chatbot, grade, download, txt, ask],
|
249 |
postprocess=False).then(
|
250 |
bot, chatbot, chatbot
|
251 |
)
|