qqwjq1981 commited on
Commit
b3317fb
·
verified ·
1 Parent(s): c60c9d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -25
app.py CHANGED
@@ -938,36 +938,32 @@ async def whatsapp_webhook(request: Request):
938
  processed_input = transcription if transcription else incoming_msg
939
 
940
  logger.debug(f"Processed input: {processed_input}")
 
941
  try:
942
- # Iterating and logging the shared state
943
- for key, value in shared_state.items():
944
- if isinstance(value, pd.DataFrame):
945
- logger.debug(f"{key}: DataFrame:\n{value.to_string()}")
946
- elif isinstance(value, dict):
947
- logger.debug(f"{key}: Dictionary: {value}")
948
- elif isinstance(value, str):
949
- logger.debug(f"{key}: String: {value}")
950
- else:
951
- logger.debug(f"{key}: Unsupported type: {value}")
952
  # Generate response
953
  project_desc_table, _ = fetch_updated_state()
954
- if not project_desc_table.empty:
955
- task_analysis_txt, execution_status, execution_results = fn_process_task(project_desc_table, processed_input)
956
- update_gradio_state(task_analysis_txt, execution_status, execution_results)
957
-
958
- doc_url = 'Fail to generate doc'
959
- if 'doc_url' in execution_results:
960
- doc_url = execution_results['doc_url']
961
-
962
- # Respond to the user on WhatsApp with the processed idea
963
- response = message_back(processed_input, execution_status, doc_url, from_number)
964
- logger.debug(response)
965
-
966
- return JSONResponse(content=str(response))
 
 
 
 
 
 
967
  except Exception as e:
968
  logger.error(f"Error during task processing: {e}")
969
- return {"error": str(e)}
970
-
971
 
972
  # In[19]:
973
 
 
938
  processed_input = transcription if transcription else incoming_msg
939
 
940
  logger.debug(f"Processed input: {processed_input}")
941
+
942
  try:
 
 
 
 
 
 
 
 
 
 
943
  # Generate response
944
  project_desc_table, _ = fetch_updated_state()
945
+
946
+ # If the project_desc_table is empty, return an empty JSON response
947
+ if project_desc_table.empty:
948
+ return JSONResponse(content={}) # Returning an empty JSON object
949
+
950
+ # Continue processing if the table is not empty
951
+ task_analysis_txt, execution_status, execution_results = fn_process_task(project_desc_table, processed_input)
952
+ update_gradio_state(task_analysis_txt, execution_status, execution_results)
953
+
954
+ doc_url = 'Fail to generate doc'
955
+ if 'doc_url' in execution_results:
956
+ doc_url = execution_results['doc_url']
957
+
958
+ # Respond to the user on WhatsApp with the processed idea
959
+ response = message_back(processed_input, execution_status, doc_url, from_number)
960
+ logger.debug(response)
961
+
962
+ return JSONResponse(content=str(response))
963
+
964
  except Exception as e:
965
  logger.error(f"Error during task processing: {e}")
966
+ return JSONResponse(content={"error": str(e)}, status_code=500)
 
967
 
968
  # In[19]:
969