Benjov commited on
Commit
ee4d989
·
1 Parent(s): a4e6e48

31/10/2023

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -343,6 +343,23 @@ def get_respuesta( user_message, informacion):
343
  return get_completion_from_messages(messages)
344
 
345
  def chat(user_message_1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  norma_y_tema_response_1 = get_topic(user_message_1)
347
  norma_y_tema_response_1 += 'Todos'
348
  uno = buscar_ai(user_message_1, list_of_dfs)
 
343
  return get_completion_from_messages(messages)
344
 
345
  def chat(user_message_1):
346
+ #
347
+ json_keyfile = os.getenv( "credentials" )
348
+ json_keyfile = json.loads( json_keyfile )
349
+ scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
350
+ credentials = ServiceAccountCredentials.from_json_keyfile_name(json_keyfile, scope)
351
+ gc = gspread.authorize(credentials)
352
+ sh = gc.open_by_url( os.getenv('Google_Sheet') )
353
+ worksheet1 = sh.get_worksheet(0)
354
+ if worksheet1 is not None:
355
+ try:
356
+ worksheet1.append_row([user_message_1]) # Append the question to the Google Sheets
357
+ print("Question successfully saved.")
358
+ except Exception as e:
359
+ print(f"Error while saving the question: {str(e)}")
360
+ else:
361
+ print("Worksheet is None. Question not saved.")
362
+ #
363
  norma_y_tema_response_1 = get_topic(user_message_1)
364
  norma_y_tema_response_1 += 'Todos'
365
  uno = buscar_ai(user_message_1, list_of_dfs)