Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -900,6 +900,150 @@ geomodel_llm = keras_nlp.models.CausalLM.from_preset("hf://ShebMichel/geobot_tea
|
|
| 900 |
# iface.launch()
|
| 901 |
|
| 902 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 903 |
import json
|
| 904 |
import gradio as gr
|
| 905 |
|
|
@@ -971,13 +1115,26 @@ 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 |
-
#
|
| 976 |
-
model_output = f"Model
|
| 977 |
return model_output
|
| 978 |
|
| 979 |
def clear_output():
|
| 980 |
-
return ""
|
| 981 |
|
| 982 |
# Create Gradio interface
|
| 983 |
with gr.Blocks() as iface:
|
|
@@ -1010,37 +1167,50 @@ with gr.Blocks() as iface:
|
|
| 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=[
|
| 1023 |
-
outputs=[
|
| 1024 |
)
|
| 1025 |
|
| 1026 |
clear_button.click(
|
| 1027 |
fn=clear_output,
|
| 1028 |
-
outputs=[
|
| 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,
|
| 1042 |
)
|
| 1043 |
|
| 1044 |
# Launch the interface
|
| 1045 |
iface.launch()
|
| 1046 |
-
|
|
|
|
| 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
|
| 1049 |
|
|
|
|
| 1115 |
# Generate output based on the selected section and show all questions in that category
|
| 1116 |
return generate_output_text(loaded_data, section=selection)
|
| 1117 |
|
| 1118 |
+
def set_question_to_edit(selection):
|
| 1119 |
+
# Sets the first question from the selected category in the edit box if available
|
| 1120 |
+
output_text = ""
|
| 1121 |
+
if selection == "MULTIPLE CHOICE QUESTIONS" and 'multiple_choice_questions' in loaded_data:
|
| 1122 |
+
first_question = list(loaded_data['multiple_choice_questions'].values())[0].get('question', '')
|
| 1123 |
+
elif selection == "SHORT ANSWER QUESTIONS" and 'short_answer_questions' in loaded_data:
|
| 1124 |
+
first_question = list(loaded_data['short_answer_questions'].values())[0].get('question', '')
|
| 1125 |
+
elif selection == "LONG ANSWER QUESTIONS" and 'long_answer_questions' in loaded_data:
|
| 1126 |
+
first_question = list(loaded_data['long_answer_questions'].values())[0].get('question', '')
|
| 1127 |
+
else:
|
| 1128 |
+
first_question = ""
|
| 1129 |
+
return first_question
|
| 1130 |
+
|
| 1131 |
def submit_question(question_content):
|
| 1132 |
+
# Simulate processing by an LLM model
|
| 1133 |
+
model_output = f"Model response to the question: {question_content[:100]}..." # Only showing part for brevity
|
| 1134 |
return model_output
|
| 1135 |
|
| 1136 |
def clear_output():
|
| 1137 |
+
return "", ""
|
| 1138 |
|
| 1139 |
# Create Gradio interface
|
| 1140 |
with gr.Blocks() as iface:
|
|
|
|
| 1167 |
outputs=[output_text]
|
| 1168 |
)
|
| 1169 |
|
| 1170 |
+
# Editable question text box
|
| 1171 |
+
with gr.Row():
|
| 1172 |
+
question_edit = gr.Textbox(
|
| 1173 |
+
label="Edit Selected Question",
|
| 1174 |
+
placeholder="Select a section and a question to edit here...",
|
| 1175 |
+
lines=4
|
| 1176 |
+
)
|
| 1177 |
+
|
| 1178 |
+
# Output box for the model's response
|
| 1179 |
+
model_response = gr.Textbox(
|
| 1180 |
+
label="Model Response",
|
| 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)
|
| 1188 |
clear_button = gr.Button("Clear", interactive=False)
|
|
|
|
| 1189 |
|
| 1190 |
# Define button actions
|
| 1191 |
+
radio_section.change(
|
| 1192 |
+
fn=set_question_to_edit,
|
| 1193 |
+
inputs=[radio_section],
|
| 1194 |
+
outputs=[question_edit]
|
| 1195 |
+
)
|
| 1196 |
+
|
| 1197 |
submit_button.click(
|
| 1198 |
fn=submit_question,
|
| 1199 |
+
inputs=[question_edit],
|
| 1200 |
+
outputs=[model_response]
|
| 1201 |
)
|
| 1202 |
|
| 1203 |
clear_button.click(
|
| 1204 |
fn=clear_output,
|
| 1205 |
+
outputs=[question_edit, model_response]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1206 |
)
|
| 1207 |
|
| 1208 |
# Process file input and enable radio buttons and buttons on successful load
|
| 1209 |
file_input.upload(
|
| 1210 |
fn=process_json_file,
|
| 1211 |
inputs=[file_input],
|
| 1212 |
+
outputs=[output_text, radio_section, radio_section, radio_section, radio_section, submit_button, clear_button, submit_button]
|
| 1213 |
)
|
| 1214 |
|
| 1215 |
# Launch the interface
|
| 1216 |
iface.launch()
|
|
|