vladyslav
commited on
Commit
·
8974ee4
1
Parent(s):
857d5df
Removing models with passed tests for book
Browse files- app.py +76 -6
- utils/db.py +6 -0
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import gradio as gr
|
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
|
| 8 |
from constants import MODELS, MODELS_PATH, BOOKS, CLASSES, STUDENTS
|
| 9 |
-
from utils import save_results
|
| 10 |
|
| 11 |
load_dotenv()
|
| 12 |
|
|
@@ -201,8 +201,48 @@ def prepare_questions_for_feedback(questions, answer_log):
|
|
| 201 |
|
| 202 |
|
| 203 |
def update_students(class_name):
|
|
|
|
| 204 |
students = STUDENTS.get(class_name, [])
|
| 205 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
with gr.Blocks() as demo:
|
| 208 |
with gr.Column():
|
|
@@ -210,8 +250,8 @@ with gr.Blocks() as demo:
|
|
| 210 |
|
| 211 |
class_name_input = gr.Dropdown(choices=CLASSES, label="Ваш клас", value=None)
|
| 212 |
student_name_input = gr.Dropdown(label="Ваше ім'я", value=None, visible=False)
|
| 213 |
-
|
| 214 |
-
|
| 215 |
load_button = gr.Button("Завантажити питання")
|
| 216 |
|
| 217 |
question_output = gr.Markdown(label="Питання")
|
|
@@ -234,10 +274,40 @@ with gr.Blocks() as demo:
|
|
| 234 |
|
| 235 |
class_name_input.change(
|
| 236 |
update_students,
|
| 237 |
-
inputs=[
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
)
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
def update_question(model, book, student_name, class_name):
|
| 242 |
question, answers = load_questions(model, book, student_name, class_name)
|
| 243 |
is_field_filled = len(answers) > 0
|
|
|
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
|
| 8 |
from constants import MODELS, MODELS_PATH, BOOKS, CLASSES, STUDENTS
|
| 9 |
+
from utils import save_results, get_test_by_student_class_book
|
| 10 |
|
| 11 |
load_dotenv()
|
| 12 |
|
|
|
|
| 201 |
|
| 202 |
|
| 203 |
def update_students(class_name):
|
| 204 |
+
print('update_students')
|
| 205 |
students = STUDENTS.get(class_name, [])
|
| 206 |
+
return (
|
| 207 |
+
gr.update(choices=students, value=None, visible=True), # student_name_input
|
| 208 |
+
gr.update(choices=[], value=None, visible=False), # book_radio
|
| 209 |
+
gr.update(choices=[], value=None, visible=False), # model_radio
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def handle_student_name_change(student_name):
|
| 214 |
+
print('handle_student_name_change')
|
| 215 |
+
if not student_name:
|
| 216 |
+
return (
|
| 217 |
+
gr.update(choices=[], value=None, visible=False), # book_radio
|
| 218 |
+
gr.update(choices=[], value=None, visible=False), # model_radio
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
return (
|
| 222 |
+
gr.update(choices=list(BOOKS.keys()), value=None, visible=True), # book_radio
|
| 223 |
+
gr.update(choices=[], value=None, visible=False), # model_radio
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def filter_models(student_name, class_name, book):
|
| 228 |
+
print('filter_models')
|
| 229 |
+
if not book:
|
| 230 |
+
return gr.update(choices=[], value=None, visible=False)
|
| 231 |
+
|
| 232 |
+
tests = get_test_by_student_class_book(student_name, class_name, book)
|
| 233 |
+
models_list = list(MODELS.values())
|
| 234 |
+
|
| 235 |
+
for test in tests:
|
| 236 |
+
if test.get("model") in models_list:
|
| 237 |
+
models_list.remove(test.get("model"))
|
| 238 |
+
|
| 239 |
+
print("Available models (before update):", models_list)
|
| 240 |
+
|
| 241 |
+
if not models_list:
|
| 242 |
+
return gr.update(choices=[], label="### Немає доступних моделей", value=None, visible=True)
|
| 243 |
+
|
| 244 |
+
return gr.update(choices=models_list, value=None, visible=True)
|
| 245 |
+
|
| 246 |
|
| 247 |
with gr.Blocks() as demo:
|
| 248 |
with gr.Column():
|
|
|
|
| 250 |
|
| 251 |
class_name_input = gr.Dropdown(choices=CLASSES, label="Ваш клас", value=None)
|
| 252 |
student_name_input = gr.Dropdown(label="Ваше ім'я", value=None, visible=False)
|
| 253 |
+
book_radio = gr.Radio([], label="Оберіть книгу", interactive=True, value=None, visible=False)
|
| 254 |
+
model_radio = gr.Radio([], label="Оберіть модель", interactive=True, value=None, visible=False)
|
| 255 |
load_button = gr.Button("Завантажити питання")
|
| 256 |
|
| 257 |
question_output = gr.Markdown(label="Питання")
|
|
|
|
| 274 |
|
| 275 |
class_name_input.change(
|
| 276 |
update_students,
|
| 277 |
+
inputs=[
|
| 278 |
+
class_name_input,
|
| 279 |
+
],
|
| 280 |
+
outputs=[
|
| 281 |
+
student_name_input,
|
| 282 |
+
book_radio,
|
| 283 |
+
model_radio,
|
| 284 |
+
]
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
student_name_input.change(
|
| 288 |
+
handle_student_name_change,
|
| 289 |
+
inputs=[
|
| 290 |
+
student_name_input,
|
| 291 |
+
],
|
| 292 |
+
outputs=[
|
| 293 |
+
book_radio,
|
| 294 |
+
model_radio,
|
| 295 |
+
]
|
| 296 |
)
|
| 297 |
|
| 298 |
+
book_radio.change(
|
| 299 |
+
filter_models,
|
| 300 |
+
inputs=[
|
| 301 |
+
student_name_input,
|
| 302 |
+
class_name_input,
|
| 303 |
+
book_radio,
|
| 304 |
+
],
|
| 305 |
+
outputs=[
|
| 306 |
+
model_radio,
|
| 307 |
+
]
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
def update_question(model, book, student_name, class_name):
|
| 312 |
question, answers = load_questions(model, book, student_name, class_name)
|
| 313 |
is_field_filled = len(answers) > 0
|
utils/db.py
CHANGED
|
@@ -51,3 +51,9 @@ def save_results(student_name,
|
|
| 51 |
"created_at": db.command("serverStatus")["localTime"]
|
| 52 |
})
|
| 53 |
print("Saved results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
"created_at": db.command("serverStatus")["localTime"]
|
| 52 |
})
|
| 53 |
print("Saved results")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def get_test_by_student_class_book(student_name, class_name, book):
|
| 57 |
+
print(f"Getting tests for student: {student_name}, class: {class_name}, book: {book}")
|
| 58 |
+
tests = collection.find({"student_name": student_name, "class": class_name, "book": book})
|
| 59 |
+
return tests
|