Update process_data.py
Browse files- process_data.py +32 -3
process_data.py
CHANGED
|
@@ -183,6 +183,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 183 |
# Call OpenAI API to generate structured output based on prompt
|
| 184 |
print("Getting all responses in pieces, starting with field response")
|
| 185 |
|
|
|
|
| 186 |
print("Field prompt")
|
| 187 |
print(field_prompt)
|
| 188 |
|
|
@@ -286,10 +287,14 @@ def generate_json_pieces(input_data, parameters):
|
|
| 286 |
print("ADDED DICTS")
|
| 287 |
print(farm_activities)
|
| 288 |
print("FINAL JSON: ")
|
| 289 |
-
|
| 290 |
-
print(
|
| 291 |
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
except Exception as e:
|
| 294 |
return {"error": "Failed to generate valid JSON. " + str(e)}
|
| 295 |
|
|
@@ -542,6 +547,22 @@ def parse_survey_stack_data(data):
|
|
| 542 |
processed_data["input_text_pieces"]["soil_data_input"] = farm_management_inputs.get('soil_data_input', {}).get('value', None)
|
| 543 |
processed_data["input_text_pieces"]["yield_data_input"] = farm_management_inputs.get('yield_data_input', {}).get('value', None)
|
| 544 |
processed_data["input_text"] = "EMPTY"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
elif processed_data["stepwise_json_creation"][0] == "singlejsoncreation":
|
| 546 |
print("IN THE SINGLE")
|
| 547 |
processed_data["input_text"] = data[0]['data']['onelonginputtext']['value']
|
|
@@ -554,6 +575,14 @@ def parse_survey_stack_data(data):
|
|
| 554 |
processed_data["input_text_pieces"]["soil_data_input"] = "EMPTY"
|
| 555 |
processed_data["input_text_pieces"]["yield_data_input"] = "EMPTY"
|
| 556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
print("RETURNING DATA")
|
| 558 |
print(processed_data)
|
| 559 |
|
|
|
|
| 183 |
# Call OpenAI API to generate structured output based on prompt
|
| 184 |
print("Getting all responses in pieces, starting with field response")
|
| 185 |
|
| 186 |
+
# All of this is for the first schema for farm activities
|
| 187 |
print("Field prompt")
|
| 188 |
print(field_prompt)
|
| 189 |
|
|
|
|
| 287 |
print("ADDED DICTS")
|
| 288 |
print(farm_activities)
|
| 289 |
print("FINAL JSON: ")
|
| 290 |
+
final_pretty_farm_activity_json = json.dumps(farm_activities, indent=4)
|
| 291 |
+
print(final_pretty_farm_activity_json)
|
| 292 |
|
| 293 |
+
|
| 294 |
+
# This is for the second schema now, interactions
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
return final_pretty_farm_activity_json, final_pretty_json, final_pretty_json
|
| 298 |
except Exception as e:
|
| 299 |
return {"error": "Failed to generate valid JSON. " + str(e)}
|
| 300 |
|
|
|
|
| 547 |
processed_data["input_text_pieces"]["soil_data_input"] = farm_management_inputs.get('soil_data_input', {}).get('value', None)
|
| 548 |
processed_data["input_text_pieces"]["yield_data_input"] = farm_management_inputs.get('yield_data_input', {}).get('value', None)
|
| 549 |
processed_data["input_text"] = "EMPTY"
|
| 550 |
+
|
| 551 |
+
print("NEXT SCHEMA INPUTS")
|
| 552 |
+
interactions_inputs = data[0]['data']['group_5']
|
| 553 |
+
print("INTERACTIONS INPUTS" + str(interactions_inputs))
|
| 554 |
+
processed_data["input_text_pieces_second_schema"] = {}
|
| 555 |
+
processed_data["input_text_pieces_second_schema"]["interaction_data_input"] = farm_management_inputs.get('interaction_data_input', {}).get('value', None)
|
| 556 |
+
processed_data["input_text_pieces_second_schema"]["person_data_input"] = farm_management_inputs.get('person_data_input', {}).get('value', None)
|
| 557 |
+
|
| 558 |
+
print("NEXT SCHEMA INPUTS 2")
|
| 559 |
+
trials_inputs = data[0]['data']['group_6']
|
| 560 |
+
print("TRIALS INPUTS" + str(trials_inputs))
|
| 561 |
+
processed_data["input_text_pieces_third_schema"] = {}
|
| 562 |
+
processed_data["input_text_pieces_third_schema"]["trial_data_input"] = farm_management_inputs.get('trial_data_input', {}).get('value', None)
|
| 563 |
+
processed_data["input_text_pieces_third_schema"]["treatment_data_input"] = farm_management_inputs.get('treatment_data_input', {}).get('value', None)
|
| 564 |
+
|
| 565 |
+
|
| 566 |
elif processed_data["stepwise_json_creation"][0] == "singlejsoncreation":
|
| 567 |
print("IN THE SINGLE")
|
| 568 |
processed_data["input_text"] = data[0]['data']['onelonginputtext']['value']
|
|
|
|
| 575 |
processed_data["input_text_pieces"]["soil_data_input"] = "EMPTY"
|
| 576 |
processed_data["input_text_pieces"]["yield_data_input"] = "EMPTY"
|
| 577 |
|
| 578 |
+
processed_data["input_text_pieces_second_schema"] = {}
|
| 579 |
+
processed_data["input_text_pieces_second_schema"]["interaction_data_input"] = "EMPTY"
|
| 580 |
+
processed_data["input_text_pieces_second_schema"]["person_data_input"] = "EMPTY"
|
| 581 |
+
|
| 582 |
+
processed_data["input_text_pieces_third_schema"] = {}
|
| 583 |
+
processed_data["input_text_pieces_third_schema"]["trial_data_input"] = "EMPTY"
|
| 584 |
+
processed_data["input_text_pieces_third_schema"]["treatment_data_input"] = "EMPTY"
|
| 585 |
+
|
| 586 |
print("RETURNING DATA")
|
| 587 |
print(processed_data)
|
| 588 |
|