ShebMichel commited on
Commit
61025a3
·
verified ·
1 Parent(s): 1ee0d68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +146 -1
app.py CHANGED
@@ -755,6 +755,151 @@ geomodel_llm = keras_nlp.models.CausalLM.from_preset("hf://ShebMichel/geobot_tea
755
  # iface.launch()
756
 
757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758
  import json
759
  import gradio as gr
760
 
@@ -823,7 +968,7 @@ def generate_output_text(data, section="ALL"):
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):
 
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
 
 
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):