akhaliq HF staff commited on
Commit
eaf2525
·
verified ·
1 Parent(s): 3936f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -10,7 +10,7 @@ def chat_with_gemini(user_api_key, user_input, history):
10
  Args:
11
  user_api_key (str): The user's Google Gemini API key (optional).
12
  user_input (str): The latest message from the user.
13
- history (list): The conversation history as a list of messages.
14
 
15
  Returns:
16
  tuple: The updated conversation history with the chatbot's reply.
@@ -20,7 +20,7 @@ def chat_with_gemini(user_api_key, user_input, history):
20
 
21
  if not api_key:
22
  # If no API key is available, prompt the user
23
- history.append("Please enter your Google Gemini API key to start the conversation.")
24
  return history, history
25
 
26
  try:
@@ -42,13 +42,13 @@ def chat_with_gemini(user_api_key, user_input, history):
42
  chatbot_reply = response.text.strip()
43
 
44
  # Append the user input and chatbot reply to the history
45
- history.append(user_input)
46
- history.append(chatbot_reply)
47
 
48
  return history, history
49
  except Exception as e:
50
  error_message = f"An error occurred: {e}"
51
- history.append(error_message)
52
  return history, history
53
 
54
  with gr.Blocks() as iface:
 
10
  Args:
11
  user_api_key (str): The user's Google Gemini API key (optional).
12
  user_input (str): The latest message from the user.
13
+ history (list): The conversation history as a list of message pairs.
14
 
15
  Returns:
16
  tuple: The updated conversation history with the chatbot's reply.
 
20
 
21
  if not api_key:
22
  # If no API key is available, prompt the user
23
+ history.append(["", "Please enter your Google Gemini API key to start the conversation."])
24
  return history, history
25
 
26
  try:
 
42
  chatbot_reply = response.text.strip()
43
 
44
  # Append the user input and chatbot reply to the history
45
+ history.append([user_input, ""]) # User message
46
+ history.append(["", chatbot_reply]) # Bot response
47
 
48
  return history, history
49
  except Exception as e:
50
  error_message = f"An error occurred: {e}"
51
+ history.append(["", error_message])
52
  return history, history
53
 
54
  with gr.Blocks() as iface: