ShebMichel commited on
Commit
8493c36
·
verified ·
1 Parent(s): abdb6c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1006
app.py CHANGED
@@ -39,1010 +39,15 @@ body::before {
39
 
40
  geomodel_llm = keras_nlp.models.CausalLM.from_preset("hf://ShebMichel/geobot_teacher-v0")
41
 
42
-
43
- # import json
44
- # import gradio as gr
45
-
46
- # def process_json_file(file):
47
- # try:
48
- # # Read and print the file content for debugging
49
- # print("File received:", file.name)
50
-
51
- # # Read the JSON file
52
- # with open(file.name, 'r') as f:
53
- # print("Reading file contents...")
54
- # json_data = json.load(f)
55
-
56
- # # Print the structure of the JSON data
57
- # print("\nJSON Structure:")
58
- # print("Available sections:", list(json_data.keys()))
59
-
60
- # # Process each section
61
- # output_text = ""
62
-
63
- # # Process header if exists
64
- # if 'header' in json_data:
65
- # output_text += "=== EXAM DETAILS ===\n"
66
- # for key, value in json_data['header'].items():
67
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
68
- # output_text += "\n"
69
-
70
- # # Process multiple choice questions
71
- # if 'multiple_choice_questions' in json_data:
72
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
73
- # for q_num, q_data in json_data['multiple_choice_questions'].items():
74
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
75
- # output_text += f"{q_data['question']}\n"
76
- # for opt_key, opt_val in q_data['options'].items():
77
- # output_text += f"{opt_key}) {opt_val}\n"
78
- # output_text += f"Answer: {q_data['answer']}\n"
79
-
80
- # # Process short answer questions
81
- # if 'short_answer_questions' in json_data:
82
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
83
- # for q_num, q_data in json_data['short_answer_questions'].items():
84
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
85
- # output_text += f"{q_data['question']}\n"
86
- # output_text += f"Answer: {q_data['answer']}\n"
87
-
88
- # # Process long answer questions
89
- # if 'long_answer_questions' in json_data:
90
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
91
- # for q_num, q_data in json_data['long_answer_questions'].items():
92
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
93
- # output_text += f"{q_data['question']}\n"
94
- # output_text += f"Answer: {q_data['answer']}\n"
95
-
96
- # print("\nProcessing complete!")
97
- # return output_text
98
-
99
- # except json.JSONDecodeError as e:
100
- # error_msg = f"Error decoding JSON: {str(e)}"
101
- # print(error_msg)
102
- # return error_msg
103
- # except Exception as e:
104
- # error_msg = f"Error processing file: {str(e)}"
105
- # print(error_msg)
106
- # return error_msg
107
-
108
- # # Create Gradio interface
109
- # with gr.Blocks() as iface:
110
- # gr.Markdown("# Exam Question Viewer")
111
-
112
- # with gr.Row():
113
- # file_input = gr.File(
114
- # label="Upload JSON Exam File",
115
- # file_types=[".json"]
116
- # )
117
-
118
- # with gr.Row():
119
- # output_text = gr.Textbox(
120
- # label="Processed Questions",
121
- # lines=20,
122
- # max_lines=30
123
- # )
124
-
125
- # file_input.upload(
126
- # fn=process_json_file,
127
- # inputs=[file_input],
128
- # outputs=[output_text]
129
- # )
130
-
131
- # # Launch the interface
132
- # iface.launch()
133
-
134
-
135
- # import json
136
- # import gradio as gr
137
-
138
- # def process_json_file(file):
139
- # try:
140
- # print("File received:", file.name)
141
-
142
- # with open(file.name, 'r') as f:
143
- # json_data = json.load(f)
144
-
145
- # print("File loaded successfully!")
146
- # return (
147
- # "File uploaded successfully!",
148
- # json_data,
149
- # # Update all radio buttons to be visible and interactive
150
- # gr.Radio.update(visible=True, interactive=True),
151
- # gr.Radio.update(visible=True, interactive=True),
152
- # gr.Radio.update(visible=True, interactive=True)
153
- # )
154
- # except Exception as e:
155
- # return (
156
- # f"Error: {str(e)}",
157
- # None,
158
- # gr.Radio.update(visible=False, interactive=False),
159
- # gr.Radio.update(visible=False, interactive=False),
160
- # gr.Radio.update(visible=False, interactive=False)
161
- # )
162
-
163
- # def display_mcq(choice, json_data):
164
- # if not json_data or not choice:
165
- # return ""
166
- # output_text = "\n=== MULTIPLE CHOICE QUESTIONS ===\n"
167
- # questions = json_data['multiple_choice_questions']
168
- # for q_num, q_data in questions.items():
169
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
170
- # output_text += f"{q_data['question']}\n"
171
- # for opt_key, opt_val in q_data['options'].items():
172
- # output_text += f"{opt_key}) {opt_val}\n"
173
- # output_text += f"Answer: {q_data['answer']}\n"
174
- # output_text += "-" * 50 + "\n"
175
- # return output_text
176
-
177
- # def display_short(choice, json_data):
178
- # if not json_data or not choice:
179
- # return ""
180
- # output_text = "\n=== SHORT ANSWER QUESTIONS ===\n"
181
- # questions = json_data['short_answer_questions']
182
- # for q_num, q_data in questions.items():
183
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
184
- # output_text += f"{q_data['question']}\n"
185
- # output_text += f"Answer: {q_data['answer']}\n"
186
- # output_text += "-" * 50 + "\n"
187
- # return output_text
188
-
189
- # def display_long(choice, json_data):
190
- # if not json_data or not choice:
191
- # return ""
192
- # output_text = "\n=== LONG ANSWER QUESTIONS ===\n"
193
- # questions = json_data['long_answer_questions']
194
- # for q_num, q_data in questions.items():
195
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
196
- # output_text += f"{q_data['question']}\n"
197
- # output_text += f"Answer: {q_data['answer']}\n"
198
- # output_text += "-" * 50 + "\n"
199
- # return output_text
200
-
201
- # # Create Gradio interface
202
- # with gr.Blocks() as iface:
203
- # gr.Markdown("# Exam Question Viewer")
204
-
205
- # # Store JSON data in state
206
- # json_state = gr.State(None)
207
-
208
- # with gr.Row():
209
- # file_input = gr.File(
210
- # label="Upload JSON Exam File",
211
- # file_types=[".json"]
212
- # )
213
- # upload_status = gr.Textbox(label="Upload Status")
214
-
215
- # with gr.Row():
216
- # with gr.Column():
217
- # mcq_radio = gr.Radio(
218
- # choices=["Show Multiple Choice Questions"],
219
- # label="Multiple Choice Questions",
220
- # visible=False,
221
- # interactive=False
222
- # )
223
- # mcq_output = gr.Textbox(
224
- # label="Multiple Choice Questions",
225
- # lines=10,
226
- # visible=True
227
- # )
228
-
229
- # with gr.Column():
230
- # short_radio = gr.Radio(
231
- # choices=["Show Short Answer Questions"],
232
- # label="Short Answer Questions",
233
- # visible=False,
234
- # interactive=False
235
- # )
236
- # short_output = gr.Textbox(
237
- # label="Short Answer Questions",
238
- # lines=10,
239
- # visible=True
240
- # )
241
-
242
- # with gr.Column():
243
- # long_radio = gr.Radio(
244
- # choices=["Show Long Answer Questions"],
245
- # label="Long Answer Questions",
246
- # visible=False,
247
- # interactive=False
248
- # )
249
- # long_output = gr.Textbox(
250
- # label="Long Answer Questions",
251
- # lines=10,
252
- # visible=True
253
- # )
254
-
255
- # # Handle file upload
256
- # file_input.upload(
257
- # fn=process_json_file,
258
- # inputs=[file_input],
259
- # outputs=[
260
- # upload_status,
261
- # json_state,
262
- # mcq_radio,
263
- # short_radio,
264
- # long_radio
265
- # ]
266
- # )
267
-
268
- # # Handle radio button selections
269
- # mcq_radio.change(
270
- # fn=display_mcq,
271
- # inputs=[mcq_radio, json_state],
272
- # outputs=[mcq_output]
273
- # )
274
-
275
- # short_radio.change(
276
- # fn=display_short,
277
- # inputs=[short_radio, json_state],
278
- # outputs=[short_output]
279
- # )
280
-
281
- # long_radio.change(
282
- # fn=display_long,
283
- # inputs=[long_radio, json_state],
284
- # outputs=[long_output]
285
- # )
286
-
287
- # # Launch the interface
288
- # iface.launch()
289
-
290
-
291
- # import json
292
- # import gradio as gr
293
-
294
- # def process_json_file(file):
295
- # try:
296
- # # Read and print the file content for debugging
297
- # print("File received:", file.name)
298
-
299
- # # Read the JSON file
300
- # with open(file.name, 'r') as f:
301
- # print("Reading file contents...")
302
- # json_data = json.load(f)
303
-
304
- # # Print the structure of the JSON data
305
- # print("\nJSON Structure:")
306
- # print("Available sections:", list(json_data.keys()))
307
-
308
- # # Process each section
309
- # output_text = ""
310
-
311
- # # Process header if exists
312
- # if 'header' in json_data:
313
- # output_text += "=== EXAM DETAILS ===\n"
314
- # for key, value in json_data['header'].items():
315
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
316
- # output_text += "\n"
317
-
318
- # # Process multiple choice questions
319
- # if 'multiple_choice_questions' in json_data:
320
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
321
- # for q_num, q_data in json_data['multiple_choice_questions'].items():
322
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
323
- # output_text += f"{q_data['question']}\n"
324
- # for opt_key, opt_val in q_data['options'].items():
325
- # output_text += f"{opt_key}) {opt_val}\n"
326
- # output_text += f"Answer: {q_data['answer']}\n"
327
-
328
- # # Process short answer questions
329
- # if 'short_answer_questions' in json_data:
330
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
331
- # for q_num, q_data in json_data['short_answer_questions'].items():
332
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
333
- # output_text += f"{q_data['question']}\n"
334
- # output_text += f"Answer: {q_data['answer']}\n"
335
-
336
- # # Process long answer questions
337
- # if 'long_answer_questions' in json_data:
338
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
339
- # for q_num, q_data in json_data['long_answer_questions'].items():
340
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
341
- # output_text += f"{q_data['question']}\n"
342
- # output_text += f"Answer: {q_data['answer']}\n"
343
-
344
- # print("\nProcessing complete!")
345
- # return output_text, gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
346
-
347
- # except json.JSONDecodeError as e:
348
- # error_msg = f"Error decoding JSON: {str(e)}"
349
- # print(error_msg)
350
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
351
- # except Exception as e:
352
- # error_msg = f"Error processing file: {str(e)}"
353
- # print(error_msg)
354
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
355
-
356
- # # Create Gradio interface
357
- # with gr.Blocks() as iface:
358
- # gr.Markdown("# Exam Question Viewer")
359
-
360
- # with gr.Row():
361
- # file_input = gr.File(
362
- # label="Upload JSON Exam File",
363
- # file_types=[".json"]
364
- # )
365
-
366
- # with gr.Row():
367
- # output_text = gr.Textbox(
368
- # label="Processed Questions",
369
- # lines=20,
370
- # max_lines=30
371
- # )
372
-
373
- # with gr.Row():
374
- # radio_qcm = gr.Radio(["QCM"], label="Select QCM", interactive=False)
375
- # radio_dtm = gr.Radio(["DTM"], label="Select DTM", interactive=False)
376
- # radio_all = gr.Radio(["ALL"], label="Select All", interactive=False)
377
-
378
- # file_input.upload(
379
- # fn=process_json_file,
380
- # inputs=[file_input],
381
- # outputs=[output_text, radio_qcm, radio_dtm, radio_all]
382
- # )
383
-
384
- # # Launch the interface
385
- # iface.launch()
386
-
387
-
388
- # import json
389
- # import gradio as gr
390
-
391
- # # Global variable to store loaded JSON data
392
- # loaded_data = {}
393
-
394
- # def process_json_file(file):
395
- # global loaded_data
396
- # try:
397
- # # Read the JSON file
398
- # with open(file.name, 'r') as f:
399
- # loaded_data = json.load(f)
400
-
401
- # # Generate the full output text
402
- # output_text = generate_output_text(loaded_data)
403
-
404
- # print("\nProcessing complete!")
405
- # # Enable radio buttons upon successful loading
406
- # return output_text, gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
407
-
408
- # except json.JSONDecodeError as e:
409
- # error_msg = f"Error decoding JSON: {str(e)}"
410
- # print(error_msg)
411
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
412
- # except Exception as e:
413
- # error_msg = f"Error processing file: {str(e)}"
414
- # print(error_msg)
415
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
416
-
417
- # def generate_output_text(data, section="ALL"):
418
- # output_text = ""
419
-
420
- # if section == "ALL" or section == "header":
421
- # if 'header' in data:
422
- # output_text += "=== EXAM DETAILS ===\n"
423
- # for key, value in data['header'].items():
424
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
425
- # output_text += "\n"
426
-
427
- # if section == "ALL" or section == "QCM":
428
- # if 'multiple_choice_questions' in data:
429
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
430
- # for q_num, q_data in data['multiple_choice_questions'].items():
431
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
432
- # output_text += f"{q_data['question']}\n"
433
- # for opt_key, opt_val in q_data['options'].items():
434
- # output_text += f"{opt_key}) {opt_val}\n"
435
- # output_text += f"Answer: {q_data['answer']}\n"
436
-
437
- # if section == "ALL" or section == "DTM":
438
- # if 'short_answer_questions' in data or 'long_answer_questions' in data:
439
- # output_text += "\n=== DETAILED QUESTIONS ===\n"
440
- # if 'short_answer_questions' in data:
441
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
442
- # for q_num, q_data in data['short_answer_questions'].items():
443
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
444
- # output_text += f"{q_data['question']}\n"
445
- # output_text += f"Answer: {q_data['answer']}\n"
446
-
447
- # if 'long_answer_questions' in data:
448
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
449
- # for q_num, q_data in data['long_answer_questions'].items():
450
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
451
- # output_text += f"{q_data['question']}\n"
452
- # output_text += f"Answer: {q_data['answer']}\n"
453
-
454
- # return output_text
455
-
456
- # def update_textbox_based_on_radio(selection):
457
- # # Generate output based on the selected section
458
- # return generate_output_text(loaded_data, section=selection)
459
-
460
- # # Create Gradio interface
461
- # with gr.Blocks() as iface:
462
- # gr.Markdown("# Exam Question Viewer")
463
-
464
- # with gr.Row():
465
- # file_input = gr.File(
466
- # label="Upload JSON Exam File",
467
- # file_types=[".json"]
468
- # )
469
-
470
- # with gr.Row():
471
- # output_text = gr.Textbox(
472
- # label="Processed Questions",
473
- # lines=20,
474
- # max_lines=30
475
- # )
476
-
477
- # with gr.Row():
478
- # radio_qcm = gr.Radio(
479
- # ["QCM", "DTM", "ALL"],
480
- # label="Select Section to Display",
481
- # interactive=False
482
- # )
483
-
484
- # # Update output_text when radio selection changes
485
- # radio_qcm.change(
486
- # fn=update_textbox_based_on_radio,
487
- # inputs=[radio_qcm],
488
- # outputs=[output_text]
489
- # )
490
-
491
- # # Process file input and enable radio buttons on successful load
492
- # file_input.upload(
493
- # fn=process_json_file,
494
- # inputs=[file_input],
495
- # outputs=[output_text, radio_qcm, radio_qcm, radio_qcm]
496
- # )
497
-
498
- # # Launch the interface
499
- # iface.launch()
500
-
501
- # import json
502
- # import gradio as gr
503
-
504
- # # Global variable to store loaded JSON data
505
- # loaded_data = {}
506
-
507
- # def process_json_file(file):
508
- # global loaded_data
509
- # try:
510
- # # Read the JSON file
511
- # with open(file.name, 'r') as f:
512
- # loaded_data = json.load(f)
513
-
514
- # # Generate the full output text
515
- # output_text = generate_output_text(loaded_data)
516
-
517
- # print("\nProcessing complete!")
518
- # # Enable radio buttons upon successful loading
519
- # return output_text, gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
520
-
521
- # except json.JSONDecodeError as e:
522
- # error_msg = f"Error decoding JSON: {str(e)}"
523
- # print(error_msg)
524
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
525
- # except Exception as e:
526
- # error_msg = f"Error processing file: {str(e)}"
527
- # print(error_msg)
528
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
529
-
530
- # def generate_output_text(data, section="ALL"):
531
- # output_text = ""
532
-
533
- # if section == "ALL" or section == "header":
534
- # if 'header' in data:
535
- # output_text += "=== EXAM DETAILS ===\n"
536
- # for key, value in data['header'].items():
537
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
538
- # output_text += "\n"
539
-
540
- # if section == "ALL" or section == "MULTIPLE CHOICE QUESTIONS":
541
- # if 'multiple_choice_questions' in data:
542
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
543
- # for q_num, q_data in data['multiple_choice_questions'].items():
544
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
545
- # output_text += f"{q_data['question']}\n"
546
- # for opt_key, opt_val in q_data['options'].items():
547
- # output_text += f"{opt_key}) {opt_val}\n"
548
- # output_text += f"Answer: {q_data['answer']}\n"
549
-
550
- # if section == "ALL" or section == "SHORT ANSWER QUESTIONS":
551
- # if 'short_answer_questions' in data:
552
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
553
- # for q_num, q_data in data['short_answer_questions'].items():
554
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
555
- # output_text += f"{q_data['question']}\n"
556
- # output_text += f"Answer: {q_data['answer']}\n"
557
-
558
- # if section == "ALL" or section == "LONG ANSWER QUESTIONS":
559
- # if 'long_answer_questions' in data:
560
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
561
- # for q_num, q_data in data['long_answer_questions'].items():
562
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
563
- # output_text += f"{q_data['question']}\n"
564
- # output_text += f"Answer: {q_data['answer']}\n"
565
-
566
- # return output_text
567
-
568
- # def update_textbox_based_on_radio(selection):
569
- # # Generate output based on the selected section
570
- # return generate_output_text(loaded_data, section=selection)
571
-
572
- # # Create Gradio interface
573
- # with gr.Blocks() as iface:
574
- # gr.Markdown("# Exam Question Viewer")
575
-
576
- # with gr.Row():
577
- # file_input = gr.File(
578
- # label="Upload JSON Exam File",
579
- # file_types=[".json"]
580
- # )
581
-
582
- # with gr.Row():
583
- # output_text = gr.Textbox(
584
- # label="Processed Questions",
585
- # lines=20,
586
- # max_lines=30
587
- # )
588
-
589
- # with gr.Row():
590
- # radio_section = gr.Radio(
591
- # ["MULTIPLE CHOICE QUESTIONS", "SHORT ANSWER QUESTIONS", "LONG ANSWER QUESTIONS", "ALL"],
592
- # label="Select Section to Display",
593
- # interactive=False
594
- # )
595
-
596
- # # Update output_text when radio selection changes
597
- # radio_section.change(
598
- # fn=update_textbox_based_on_radio,
599
- # inputs=[radio_section],
600
- # outputs=[output_text]
601
- # )
602
-
603
- # # Process file input and enable radio buttons on successful load
604
- # file_input.upload(
605
- # fn=process_json_file,
606
- # inputs=[file_input],
607
- # outputs=[output_text, radio_section, radio_section, radio_section, radio_section]
608
- # )
609
-
610
- # # Launch the interface
611
- # iface.launch()
612
-
613
- # import json
614
- # import gradio as gr
615
-
616
- # # Global variable to store loaded JSON data
617
- # loaded_data = {}
618
-
619
- # def process_json_file(file):
620
- # global loaded_data
621
- # try:
622
- # # Read the JSON file
623
- # with open(file.name, 'r') as f:
624
- # loaded_data = json.load(f)
625
-
626
- # # Generate the full output text
627
- # output_text = generate_output_text(loaded_data)
628
-
629
- # print("\nProcessing complete!")
630
- # # Enable radio buttons and buttons upon successful loading
631
- # return output_text, gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
632
-
633
- # except json.JSONDecodeError as e:
634
- # error_msg = f"Error decoding JSON: {str(e)}"
635
- # print(error_msg)
636
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
637
- # except Exception as e:
638
- # error_msg = f"Error processing file: {str(e)}"
639
- # print(error_msg)
640
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
641
-
642
- # def generate_output_text(data, section="ALL"):
643
- # output_text = ""
644
-
645
- # if section == "ALL" or section == "header":
646
- # if 'header' in data:
647
- # output_text += "=== EXAM DETAILS ===\n"
648
- # for key, value in data['header'].items():
649
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
650
- # output_text += "\n"
651
-
652
- # if section == "ALL" or section == "MULTIPLE CHOICE QUESTIONS":
653
- # if 'multiple_choice_questions' in data:
654
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
655
- # for q_num, q_data in data['multiple_choice_questions'].items():
656
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
657
- # output_text += f"{q_data['question']}\n"
658
- # for opt_key, opt_val in q_data['options'].items():
659
- # output_text += f"{opt_key}) {opt_val}\n"
660
- # output_text += f"Answer: {q_data['answer']}\n"
661
-
662
- # if section == "ALL" or section == "SHORT ANSWER QUESTIONS":
663
- # if 'short_answer_questions' in data:
664
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
665
- # for q_num, q_data in data['short_answer_questions'].items():
666
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
667
- # output_text += f"{q_data['question']}\n"
668
- # output_text += f"Answer: {q_data['answer']}\n"
669
-
670
- # if section == "ALL" or section == "LONG ANSWER QUESTIONS":
671
- # if 'long_answer_questions' in data:
672
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
673
- # for q_num, q_data in data['long_answer_questions'].items():
674
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
675
- # output_text += f"{q_data['question']}\n"
676
- # output_text += f"Answer: {q_data['answer']}\n"
677
-
678
- # return output_text
679
-
680
- # def update_textbox_based_on_radio(selection):
681
- # # Generate output based on the selected section
682
- # return generate_output_text(loaded_data, section=selection)
683
-
684
- # def submit_question(question_content):
685
- # # Placeholder model processing
686
- # model_output = f"Model processed question: {question_content[:100]}..." # Only showing part for brevity
687
- # return model_output
688
-
689
- # def clear_output():
690
- # return ""
691
-
692
- # # Create Gradio interface
693
- # with gr.Blocks() as iface:
694
- # gr.Markdown("# Exam Question Viewer")
695
-
696
- # with gr.Row():
697
- # file_input = gr.File(
698
- # label="Upload JSON Exam File",
699
- # file_types=[".json"]
700
- # )
701
-
702
- # with gr.Row():
703
- # output_text = gr.Textbox(
704
- # label="Processed Questions",
705
- # lines=20,
706
- # max_lines=30
707
- # )
708
-
709
- # with gr.Row():
710
- # radio_section = gr.Radio(
711
- # ["MULTIPLE CHOICE QUESTIONS", "SHORT ANSWER QUESTIONS", "LONG ANSWER QUESTIONS", "ALL"],
712
- # label="Select Section to Display",
713
- # interactive=False
714
- # )
715
-
716
- # # Update output_text when radio selection changes
717
- # radio_section.change(
718
- # fn=update_textbox_based_on_radio,
719
- # inputs=[radio_section],
720
- # outputs=[output_text]
721
- # )
722
-
723
- # # Submit button - Passes selected question to the model
724
- # with gr.Row():
725
- # submit_button = gr.Button("Submit", interactive=False)
726
- # clear_button = gr.Button("Clear", interactive=False)
727
- # output_button = gr.Button("Output", interactive=False)
728
-
729
- # # Define button actions
730
- # submit_button.click(
731
- # fn=submit_question,
732
- # inputs=[output_text],
733
- # outputs=[output_text]
734
- # )
735
-
736
- # clear_button.click(
737
- # fn=clear_output,
738
- # outputs=[output_text]
739
- # )
740
-
741
- # output_button.click(
742
- # fn=update_textbox_based_on_radio,
743
- # inputs=[radio_section],
744
- # outputs=[output_text]
745
- # )
746
-
747
- # # Process file input and enable radio buttons and buttons on successful load
748
- # file_input.upload(
749
- # fn=process_json_file,
750
- # inputs=[file_input],
751
- # outputs=[output_text, radio_section, radio_section, radio_section, radio_section, submit_button, clear_button, output_button]
752
- # )
753
-
754
- # # Launch the interface
755
- # iface.launch()
756
-
757
-
758
- # import json
759
- # import gradio as gr
760
-
761
- # # Global variable to store loaded JSON data
762
- # loaded_data = {}
763
-
764
- # def process_json_file(file):
765
- # global loaded_data
766
- # try:
767
- # # Read the JSON file
768
- # with open(file.name, 'r') as f:
769
- # loaded_data = json.load(f)
770
-
771
- # # Generate the full output text
772
- # output_text = generate_output_text(loaded_data)
773
-
774
- # print("\nProcessing complete!")
775
- # # Enable radio buttons and buttons upon successful loading
776
- # return output_text, gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
777
-
778
- # except json.JSONDecodeError as e:
779
- # error_msg = f"Error decoding JSON: {str(e)}"
780
- # print(error_msg)
781
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
782
- # except Exception as e:
783
- # error_msg = f"Error processing file: {str(e)}"
784
- # print(error_msg)
785
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
786
-
787
- # def generate_output_text(data, section="ALL"):
788
- # output_text = ""
789
-
790
- # if section == "ALL" or section == "header":
791
- # if 'header' in data:
792
- # output_text += "=== EXAM DETAILS ===\n"
793
- # for key, value in data['header'].items():
794
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
795
- # output_text += "\n"
796
-
797
- # if section == "ALL" or section == "MULTIPLE CHOICE QUESTIONS":
798
- # if 'multiple_choice_questions' in data:
799
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
800
- # for q_num, q_data in data['multiple_choice_questions'].items():
801
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
802
- # output_text += f"{q_data['question']}\n"
803
- # for opt_key, opt_val in q_data['options'].items():
804
- # output_text += f"{opt_key}) {opt_val}\n"
805
- # output_text += f"Answer: {q_data['answer']}\n"
806
-
807
- # if section == "ALL" or section == "SHORT ANSWER QUESTIONS":
808
- # if 'short_answer_questions' in data:
809
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
810
- # for q_num, q_data in data['short_answer_questions'].items():
811
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
812
- # output_text += f"{q_data['question']}\n"
813
- # output_text += f"Answer: {q_data['answer']}\n"
814
-
815
- # if section == "ALL" or section == "LONG ANSWER QUESTIONS":
816
- # if 'long_answer_questions' in data:
817
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
818
- # for q_num, q_data in data['long_answer_questions'].items():
819
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
820
- # output_text += f"{q_data['question']}\n"
821
- # output_text += f"Answer: {q_data['answer']}\n"
822
-
823
- # return output_text
824
-
825
- # def update_textbox_based_on_radio(selection):
826
- # # Generate output based on the selected section
827
- # return generate_output_text(loaded_data, section=selection)
828
-
829
- # def submit_question(question_content):
830
- # # Placeholder model processing
831
- # model_output = f"Model processed question: {question_content[:100]}..." # Only showing part for brevity
832
- # return model_output
833
-
834
- # def clear_output():
835
- # return ""
836
-
837
- # # Create Gradio interface
838
- # with gr.Blocks() as iface:
839
- # gr.Markdown("# Exam Question Viewer")
840
-
841
- # with gr.Row():
842
- # file_input = gr.File(
843
- # label="Upload JSON Exam File",
844
- # file_types=[".json"]
845
- # )
846
-
847
- # with gr.Row():
848
- # output_text = gr.Textbox(
849
- # label="Processed Questions",
850
- # lines=20,
851
- # max_lines=30
852
- # )
853
-
854
- # with gr.Row():
855
- # radio_section = gr.Radio(
856
- # ["MULTIPLE CHOICE QUESTIONS", "SHORT ANSWER QUESTIONS", "LONG ANSWER QUESTIONS", "ALL"],
857
- # label="Select Section to Display",
858
- # interactive=False
859
- # )
860
-
861
- # # Update output_text when radio selection changes
862
- # radio_section.change(
863
- # fn=update_textbox_based_on_radio,
864
- # inputs=[radio_section],
865
- # outputs=[output_text]
866
- # )
867
-
868
- # # Submit button - Passes selected question to the model
869
- # with gr.Row():
870
- # submit_button = gr.Button("Submit", interactive=False)
871
- # clear_button = gr.Button("Clear", interactive=False)
872
- # output_button = gr.Button("Output", interactive=False)
873
-
874
- # # Define button actions
875
- # submit_button.click(
876
- # fn=submit_question,
877
- # inputs=[output_text],
878
- # outputs=[output_text]
879
- # )
880
-
881
- # clear_button.click(
882
- # fn=clear_output,
883
- # outputs=[output_text]
884
- # )
885
-
886
- # output_button.click(
887
- # fn=update_textbox_based_on_radio,
888
- # inputs=[radio_section],
889
- # outputs=[output_text]
890
- # )
891
-
892
- # # Process file input and enable radio buttons and buttons on successful load
893
- # file_input.upload(
894
- # fn=process_json_file,
895
- # inputs=[file_input],
896
- # outputs=[output_text, radio_section, radio_section, radio_section, radio_section, submit_button, clear_button, output_button]
897
- # )
898
-
899
- # # Launch the interface
900
- # iface.launch()
901
-
902
-
903
- # import json
904
- # import gradio as gr
905
-
906
- # # Global variable to store loaded JSON data
907
- # loaded_data = {}
908
-
909
- # def process_json_file(file):
910
- # global loaded_data
911
- # try:
912
- # # Read the JSON file
913
- # with open(file.name, 'r') as f:
914
- # loaded_data = json.load(f)
915
-
916
- # # Generate the full output text
917
- # output_text = generate_output_text(loaded_data)
918
-
919
- # print("\nProcessing complete!")
920
- # # Enable radio buttons and buttons upon successful loading
921
- # return output_text, gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
922
-
923
- # except json.JSONDecodeError as e:
924
- # error_msg = f"Error decoding JSON: {str(e)}"
925
- # print(error_msg)
926
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
927
- # except Exception as e:
928
- # error_msg = f"Error processing file: {str(e)}"
929
- # print(error_msg)
930
- # return error_msg, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
931
-
932
- # def generate_output_text(data, section="ALL"):
933
- # output_text = ""
934
-
935
- # if section == "ALL" or section == "header":
936
- # if 'header' in data:
937
- # output_text += "=== EXAM DETAILS ===\n"
938
- # for key, value in data['header'].items():
939
- # output_text += f"{key.replace('_', ' ').title()}: {value}\n"
940
- # output_text += "\n"
941
-
942
- # if section == "ALL" or section == "MULTIPLE CHOICE QUESTIONS":
943
- # if 'multiple_choice_questions' in data:
944
- # output_text += "=== MULTIPLE CHOICE QUESTIONS ===\n"
945
- # for q_num, q_data in data['multiple_choice_questions'].items():
946
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
947
- # output_text += f"{q_data['question']}\n"
948
- # for opt_key, opt_val in q_data['options'].items():
949
- # output_text += f"{opt_key}) {opt_val}\n"
950
- # output_text += f"Answer: {q_data['answer']}\n"
951
-
952
- # if section == "ALL" or section == "SHORT ANSWER QUESTIONS":
953
- # if 'short_answer_questions' in data:
954
- # output_text += "\n=== SHORT ANSWER QUESTIONS ===\n"
955
- # for q_num, q_data in data['short_answer_questions'].items():
956
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
957
- # output_text += f"{q_data['question']}\n"
958
- # output_text += f"Answer: {q_data['answer']}\n"
959
-
960
- # if section == "ALL" or section == "LONG ANSWER QUESTIONS":
961
- # if 'long_answer_questions' in data:
962
- # output_text += "\n=== LONG ANSWER QUESTIONS ===\n"
963
- # for q_num, q_data in data['long_answer_questions'].items():
964
- # output_text += f"\nQuestion {q_num.replace('question', '')}:\n"
965
- # output_text += f"{q_data['question']}\n"
966
- # output_text += f"Answer: {q_data['answer']}\n"
967
-
968
- # return output_text
969
-
970
- # def update_textbox_based_on_radio(selection):
971
- # # Generate output based on the selected section and show all questions in that category
972
- # return generate_output_text(loaded_data, section=selection)
973
-
974
- # def submit_question(question_content):
975
- # # Placeholder model processing
976
- # model_output = f"Model processed question: {question_content[:100]}..." # Only showing part for brevity
977
- # return model_output
978
-
979
- # def clear_output():
980
- # return ""
981
-
982
- # # Create Gradio interface
983
- # with gr.Blocks() as iface:
984
- # gr.Markdown("# Exam Question Viewer")
985
-
986
- # with gr.Row():
987
- # file_input = gr.File(
988
- # label="Upload JSON Exam File",
989
- # file_types=[".json"]
990
- # )
991
-
992
- # with gr.Row():
993
- # output_text = gr.Textbox(
994
- # label="Processed Questions",
995
- # lines=20,
996
- # max_lines=30
997
- # )
998
-
999
- # with gr.Row():
1000
- # radio_section = gr.Radio(
1001
- # ["MULTIPLE CHOICE QUESTIONS", "SHORT ANSWER QUESTIONS", "LONG ANSWER QUESTIONS", "ALL"],
1002
- # label="Select Section to Display",
1003
- # interactive=False
1004
- # )
1005
-
1006
- # # Update output_text when radio selection changes
1007
- # radio_section.change(
1008
- # fn=update_textbox_based_on_radio,
1009
- # inputs=[radio_section],
1010
- # outputs=[output_text]
1011
- # )
1012
-
1013
- # # Submit button - Passes selected question to the model
1014
- # with gr.Row():
1015
- # submit_button = gr.Button("Submit", interactive=False)
1016
- # clear_button = gr.Button("Clear", interactive=False)
1017
- # output_button = gr.Button("Output", interactive=False)
1018
-
1019
- # # Define button actions
1020
- # submit_button.click(
1021
- # fn=submit_question,
1022
- # inputs=[output_text],
1023
- # outputs=[output_text]
1024
- # )
1025
-
1026
- # clear_button.click(
1027
- # fn=clear_output,
1028
- # outputs=[output_text]
1029
- # )
1030
-
1031
- # output_button.click(
1032
- # fn=update_textbox_based_on_radio,
1033
- # inputs=[radio_section],
1034
- # outputs=[output_text]
1035
- # )
1036
-
1037
- # # Process file input and enable radio buttons and buttons on successful load
1038
- # file_input.upload(
1039
- # fn=process_json_file,
1040
- # inputs=[file_input],
1041
- # outputs=[output_text, radio_section, radio_section, radio_section, radio_section, submit_button, clear_button, output_button]
1042
- # )
1043
-
1044
- # # Launch the interface
1045
- # iface.launch()
1046
 
1047
  import json
1048
  import gradio as gr
@@ -1181,7 +186,17 @@ with gr.Blocks() as iface:
1181
  lines=4,
1182
  interactive=False
1183
  )
1184
-
 
 
 
 
 
 
 
 
 
 
1185
  # Submit button - Passes selected question to the model
1186
  with gr.Row():
1187
  submit_button = gr.Button("Submit", interactive=False)
@@ -1191,7 +206,7 @@ with gr.Blocks() as iface:
1191
  radio_section.change(
1192
  fn=set_question_to_edit,
1193
  inputs=[radio_section],
1194
- outputs=[question_edit]
1195
  )
1196
 
1197
  submit_button.click(
 
39
 
40
  geomodel_llm = keras_nlp.models.CausalLM.from_preset("hf://ShebMichel/geobot_teacher-v0")
41
 
42
+ def launch(input):
43
+ template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
44
+ prompt = template.format(
45
+ instruction=input,
46
+ response="",
47
+ )
48
+ out = gemma_lm.generate(prompt, max_length=1024)
49
+ ind = out.index('Response') + len('Response')+2
50
+ return out[ind:]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  import json
53
  import gradio as gr
 
186
  lines=4,
187
  interactive=False
188
  )
189
+ # ### Mode; response here:
190
+ # Question_prompt="How do sedimentary rocks form?"
191
+ # template = "Question:\n{Question}\n\nResponse:\n{Response}"
192
+ # prompt = template.format(
193
+ # Question=Question_prompt,
194
+ # Response="",
195
+ # )
196
+ # sampler = keras_nlp.samplers.TopKSampler(k=2, seed=1)
197
+ # geomodel_llm.compile(sampler=sampler)
198
+ # print(gemma_lm.generate(prompt, max_length=256))
199
+
200
  # Submit button - Passes selected question to the model
201
  with gr.Row():
202
  submit_button = gr.Button("Submit", interactive=False)
 
206
  radio_section.change(
207
  fn=set_question_to_edit,
208
  inputs=[radio_section],
209
+ outputs=launch #[question_edit]
210
  )
211
 
212
  submit_button.click(