elaineaishophouse commited on
Commit
148ad1e
·
verified ·
1 Parent(s): 449c0f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -64
app.py CHANGED
@@ -204,70 +204,7 @@ A culturally authentic and conversational response to the question: '{question}'
204
 
205
  return responses
206
 
207
-
208
- # MAIN
209
- if __name__ == "__main__":
210
- # Config.load_environment(".", "genz.dev1")
211
- # Config.print_environment()
212
-
213
- # processor_llm = get_processor_llm_instance()
214
- # respondent_agent_llm = get_respondent_agent_llm_instance()
215
-
216
- logging.info("Loading environment...")
217
- Config.load_environment(".", "genz.dev1")
218
-
219
- logging.info("Environment loaded. Printing environment:")
220
- Config.print_environment()
221
-
222
- logging.info("Initializing processor_llm...")
223
- processor_llm = get_processor_llm_instance()
224
- logging.info("processor_llm initialized.")
225
-
226
- logging.info("Initializing respondent_agent_llm...")
227
- respondent_agent_llm = get_respondent_agent_llm_instance()
228
- logging.info("respondent_agent_llm initialised.")
229
-
230
- # Load all user profiles from the Excel file
231
- data_dictionary = DataDictionary.generate_dictionary(Config.data_dictionary_file)
232
- logging.info(f"Generated data dictionary: {data_dictionary}")
233
- personality_assessment = PVAssessment.generate_personality_assessment(Config.personality_question_file)
234
- logging.info(f"Generated personality_assessment: {data_dictionary}")
235
- respondent_agent_user_profiles = UserProfile.read_user_profiles_from_excel(Config.respondent_details_file, data_dictionary, personality_assessment)
236
-
237
- # Create respondent agents for all profiles
238
- respondent_agents_dict = {
239
- profile.get_field("Demographics", "Name"): RespondentAgent.create(
240
- profile, f"{Config.config_dir}/fastfacts/{profile.ID}_fast_facts.xlsx", respondent_agent_llm
241
- )
242
- for profile in respondent_agent_user_profiles[:5]
243
- }
244
-
245
- def chatbot_interface(message, history=None):
246
- """
247
- Handles chatbot interaction. Can be used both in Gradio and from MAIN.
248
- """
249
- if history is None:
250
- history = [] # Ensure history is initialized
251
-
252
- responses = ask_interview_question(respondent_agents_dict, message, processor_llm)
253
- logging.info(f"Interview response is {responses}")
254
-
255
- # Ensure responses is always a list
256
- if not isinstance(responses, list):
257
- responses = [responses] # Wrap single response in a list
258
-
259
- # Format each response properly
260
- formatted_responses = []
261
- for r in responses:
262
- formatted_responses.append({"role": "assistant", "content": str(r)})
263
-
264
- # Append user message and formatted responses to history
265
- history.append({"role": "user", "content": message})
266
- history.extend(formatted_responses) # Add each response separately
267
-
268
- logging.info(f"Return history: {history}")
269
- return history, ""
270
-
271
  custom_css = """
272
  body {
273
  background-color: A9A9A9;
@@ -400,5 +337,64 @@ if __name__ == "__main__":
400
  style="text-decoration: none; color: #007bff;">hello@predata.ai</a>
401
  </div>
402
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  demo.launch(debug=True)
 
204
 
205
  return responses
206
 
207
+ def build_interface():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  custom_css = """
209
  body {
210
  background-color: A9A9A9;
 
337
  style="text-decoration: none; color: #007bff;">hello@predata.ai</a>
338
  </div>
339
  """)
340
+ return demo
341
+
342
+ # MAIN
343
+ if __name__ == "__main__":
344
+ logging.info("Loading environment...")
345
+ Config.load_environment(".", "genz.dev1")
346
+
347
+ logging.info("Environment loaded. Printing environment:")
348
+ Config.print_environment()
349
+
350
+ logging.info("Initializing processor_llm...")
351
+ processor_llm = get_processor_llm_instance()
352
+ logging.info("processor_llm initialized.")
353
+
354
+ logging.info("Initializing respondent_agent_llm...")
355
+ respondent_agent_llm = get_respondent_agent_llm_instance()
356
+ logging.info("respondent_agent_llm initialised.")
357
+
358
+ # Load all user profiles from the Excel file
359
+ data_dictionary = DataDictionary.generate_dictionary(Config.data_dictionary_file)
360
+ logging.info(f"Generated data dictionary: {data_dictionary}")
361
+ personality_assessment = PVAssessment.generate_personality_assessment(Config.personality_question_file)
362
+ logging.info(f"Generated personality_assessment: {data_dictionary}")
363
+ respondent_agent_user_profiles = UserProfile.read_user_profiles_from_excel(Config.respondent_details_file, data_dictionary, personality_assessment)
364
+
365
+ # Create respondent agents for all profiles
366
+ respondent_agents_dict = {
367
+ profile.get_field("Demographics", "Name"): RespondentAgent.create(
368
+ profile, f"{Config.config_dir}/fastfacts/{profile.ID}_fast_facts.xlsx", respondent_agent_llm
369
+ )
370
+ for profile in respondent_agent_user_profiles[:5]
371
+ }
372
 
373
+ def chatbot_interface(message, history=None):
374
+ """
375
+ Handles chatbot interaction. Can be used both in Gradio and from MAIN.
376
+ """
377
+ if history is None:
378
+ history = [] # Ensure history is initialized
379
+
380
+ responses = ask_interview_question(respondent_agents_dict, message, processor_llm)
381
+ logging.info(f"Interview response is {responses}")
382
+
383
+ # Ensure responses is always a list
384
+ if not isinstance(responses, list):
385
+ responses = [responses] # Wrap single response in a list
386
+
387
+ # Format each response properly
388
+ formatted_responses = []
389
+ for r in responses:
390
+ formatted_responses.append({"role": "assistant", "content": str(r)})
391
+
392
+ # Append user message and formatted responses to history
393
+ history.append({"role": "user", "content": message})
394
+ history.extend(formatted_responses) # Add each response separately
395
+
396
+ logging.info(f"Return history: {history}")
397
+ return history, ""
398
+
399
+ demo = build_interface()
400
  demo.launch(debug=True)