Spaces:
Sleeping
Sleeping
hints.append({"content": question_json[hint_key], "images": {}, "widgets": {}})
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ import io
|
|
| 13 |
|
| 14 |
|
| 15 |
is_env_local = os.getenv("IS_ENV_LOCAL", "false") == "true"
|
|
|
|
| 16 |
print(f"is_env_local: {is_env_local}")
|
| 17 |
|
| 18 |
if is_env_local:
|
|
@@ -142,7 +143,58 @@ def build_perseus_json(question_json):
|
|
| 142 |
choice_2 = question_json['choice_2']
|
| 143 |
choice_3 = question_json['choice_3']
|
| 144 |
choice_4 = question_json['choice_4']
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
perseus_json = json.loads(perseus_text)
|
| 147 |
widget = "\n\n[[โ radio 1]]"
|
| 148 |
perseus_json["question"]["content"] = question + widget
|
|
@@ -150,6 +202,9 @@ def build_perseus_json(question_json):
|
|
| 150 |
perseus_json["question"]["widgets"]["radio 1"]["options"]["choices"][1]["content"] = "$\\mbox{(B)}$ " + choice_2
|
| 151 |
perseus_json["question"]["widgets"]["radio 1"]["options"]["choices"][2]["content"] = "$\\mbox{(C)}$ " + choice_3
|
| 152 |
perseus_json["question"]["widgets"]["radio 1"]["options"]["choices"][3]["content"] = "$\\mbox{(D)}$ " + choice_4
|
|
|
|
|
|
|
|
|
|
| 153 |
perseus_json_str = json.dumps(perseus_json)
|
| 154 |
return perseus_json_str
|
| 155 |
|
|
@@ -168,7 +223,7 @@ def create_csv(processed_data):
|
|
| 168 |
writer = csv.writer(file)
|
| 169 |
|
| 170 |
# ๅๅ
ฅๆ ้ข่ก
|
| 171 |
-
headers = ["ๅ็URL", "ๆๅญ", "้ก่", "้ก็ฎ", "้ธ้
1", "้ธ้
2", "้ธ้
3", "้ธ้
4", "Perseus JSON"]
|
| 172 |
writer.writerow(headers)
|
| 173 |
|
| 174 |
# ๅๅ
ฅๆฐๆฎ่ก
|
|
@@ -213,8 +268,8 @@ with gr.Blocks() as demo:
|
|
| 213 |
result_text = gr.Textbox(label="่็็ตๆ")
|
| 214 |
with gr.Row():
|
| 215 |
result_table = gr.Dataframe(
|
| 216 |
-
headers=["ๅ็URL", "ๆๅญ", "้ก่", "้ก็ฎ", "้ธ้
1", "้ธ้
2", "้ธ้
3", "้ธ้
4", "Perseus JSON"],
|
| 217 |
-
column_widths=[10,
|
| 218 |
wrap=True
|
| 219 |
)
|
| 220 |
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
is_env_local = os.getenv("IS_ENV_LOCAL", "false") == "true"
|
| 16 |
+
|
| 17 |
print(f"is_env_local: {is_env_local}")
|
| 18 |
|
| 19 |
if is_env_local:
|
|
|
|
| 143 |
choice_2 = question_json['choice_2']
|
| 144 |
choice_3 = question_json['choice_3']
|
| 145 |
choice_4 = question_json['choice_4']
|
| 146 |
+
|
| 147 |
+
hints = []
|
| 148 |
+
for i in range(1, 6):
|
| 149 |
+
hint_key = f'hint_{i}'
|
| 150 |
+
if hint_key in question_json:
|
| 151 |
+
hints.append({"content": question_json[hint_key], "images": {}, "widgets": {}})
|
| 152 |
+
else:
|
| 153 |
+
break
|
| 154 |
+
|
| 155 |
+
perseus_text = """{
|
| 156 |
+
"correct_nxt_qid": null,
|
| 157 |
+
"wrong_nxt_qid": null,
|
| 158 |
+
"itemDataVersion": {
|
| 159 |
+
"major": 0,
|
| 160 |
+
"minor": 1
|
| 161 |
+
},
|
| 162 |
+
"question": {
|
| 163 |
+
"content": "",
|
| 164 |
+
"images": {},
|
| 165 |
+
"widgets": {
|
| 166 |
+
"radio 1": {
|
| 167 |
+
"version": {
|
| 168 |
+
"major": 0,
|
| 169 |
+
"minor": 0
|
| 170 |
+
},
|
| 171 |
+
"type": "radio",
|
| 172 |
+
"graded": true,
|
| 173 |
+
"options": {
|
| 174 |
+
"onePerLine": true,
|
| 175 |
+
"noneOfTheAbove": false,
|
| 176 |
+
"choices": [
|
| 177 |
+
{"content": "", "correct": false},
|
| 178 |
+
{"content": "", "correct": false},
|
| 179 |
+
{"content": "", "correct": false},
|
| 180 |
+
{"content": "", "correct": false}
|
| 181 |
+
],
|
| 182 |
+
"displayCount": null,
|
| 183 |
+
"multipleSelect": false,
|
| 184 |
+
"randomize": false
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
},
|
| 189 |
+
"answerArea": {
|
| 190 |
+
"calculator": false,
|
| 191 |
+
"type": "multiple",
|
| 192 |
+
"options": {}
|
| 193 |
+
},
|
| 194 |
+
"is_start": false,
|
| 195 |
+
"hints": []
|
| 196 |
+
}"""
|
| 197 |
+
|
| 198 |
perseus_json = json.loads(perseus_text)
|
| 199 |
widget = "\n\n[[โ radio 1]]"
|
| 200 |
perseus_json["question"]["content"] = question + widget
|
|
|
|
| 202 |
perseus_json["question"]["widgets"]["radio 1"]["options"]["choices"][1]["content"] = "$\\mbox{(B)}$ " + choice_2
|
| 203 |
perseus_json["question"]["widgets"]["radio 1"]["options"]["choices"][2]["content"] = "$\\mbox{(C)}$ " + choice_3
|
| 204 |
perseus_json["question"]["widgets"]["radio 1"]["options"]["choices"][3]["content"] = "$\\mbox{(D)}$ " + choice_4
|
| 205 |
+
|
| 206 |
+
perseus_json["hints"] = hints
|
| 207 |
+
|
| 208 |
perseus_json_str = json.dumps(perseus_json)
|
| 209 |
return perseus_json_str
|
| 210 |
|
|
|
|
| 223 |
writer = csv.writer(file)
|
| 224 |
|
| 225 |
# ๅๅ
ฅๆ ้ข่ก
|
| 226 |
+
headers = ["ๅ็URL", "ๆๅญ", "้ก่", "้ก็ฎ", "้ธ้
1", "้ธ้
2", "้ธ้
3", "้ธ้
4", "ๆ็คบ1", "ๆ็คบ2", "ๆ็คบ3", "ๆ็คบ4", "ๆ็คบ5", "Perseus JSON"]
|
| 227 |
writer.writerow(headers)
|
| 228 |
|
| 229 |
# ๅๅ
ฅๆฐๆฎ่ก
|
|
|
|
| 268 |
result_text = gr.Textbox(label="่็็ตๆ")
|
| 269 |
with gr.Row():
|
| 270 |
result_table = gr.Dataframe(
|
| 271 |
+
headers=["ๅ็URL", "ๆๅญ", "้ก่", "้ก็ฎ", "้ธ้
1", "้ธ้
2", "้ธ้
3", "้ธ้
4", "ๆ็คบ1", "ๆ็คบ2", "ๆ็คบ3", "ๆ็คบ4", "ๆ็คบ5", "Perseus JSON"],
|
| 272 |
+
column_widths=[10, 10, 5, 20, 5, 5, 5, 5, 4,4,4,4,4, 10],
|
| 273 |
wrap=True
|
| 274 |
)
|
| 275 |
|