Reality123b commited on
Commit
81e3034
·
verified ·
1 Parent(s): c968936

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -54,17 +54,25 @@ def chat_interface():
54
  send_button = gr.Button("Send", elem_id="send-btn")
55
 
56
  def submit_input(user_input, chat_history):
57
- chat_history.append((user_input, ""))
 
 
 
58
  return "", chat_history # Clear input field
59
 
60
  input_textbox.submit(submit_input, [input_textbox, chat_output], [input_textbox, chat_output])
61
  send_button.click(submit_input, [input_textbox, chat_output], [input_textbox, chat_output])
62
 
63
  def handle_response(user_input, chat_history):
64
- chat_history[-1] = (user_input, "") # Update the last chat with user input
 
 
 
 
65
  response_stream = get_response(user_input)
66
  for partial_response in response_stream:
67
- chat_history[-1] = (user_input, partial_response)
 
68
  yield "", chat_history # Return the updated chat history progressively
69
 
70
  input_textbox.submit(handle_response, [input_textbox, chat_output], [input_textbox, chat_output])
@@ -76,13 +84,16 @@ def chat_interface():
76
  bottom: 10px;
77
  width: 100%;
78
  padding: 10px;
79
- background-color: #f5f5f5;
80
  border-top: 1px solid #ddd;
81
  }
82
  #chat-box {
83
  height: calc(100vh - 100px); /* Adjust the height of chat history */
84
  overflow-y: scroll;
85
  }
 
 
 
86
  """
87
 
88
  return demo
 
54
  send_button = gr.Button("Send", elem_id="send-btn")
55
 
56
  def submit_input(user_input, chat_history):
57
+ # Initialize the chat history if it's empty
58
+ if not chat_history:
59
+ chat_history = []
60
+ chat_history.append({"role": "user", "content": user_input})
61
  return "", chat_history # Clear input field
62
 
63
  input_textbox.submit(submit_input, [input_textbox, chat_output], [input_textbox, chat_output])
64
  send_button.click(submit_input, [input_textbox, chat_output], [input_textbox, chat_output])
65
 
66
  def handle_response(user_input, chat_history):
67
+ # Initialize the chat history if it's empty
68
+ if not chat_history:
69
+ chat_history = []
70
+ chat_history.append({"role": "user", "content": user_input})
71
+
72
  response_stream = get_response(user_input)
73
  for partial_response in response_stream:
74
+ chat_history[-1] = {"role": "user", "content": user_input} # Update the last user message with content
75
+ chat_history.append({"role": "assistant", "content": partial_response}) # Add assistant's response
76
  yield "", chat_history # Return the updated chat history progressively
77
 
78
  input_textbox.submit(handle_response, [input_textbox, chat_output], [input_textbox, chat_output])
 
84
  bottom: 10px;
85
  width: 100%;
86
  padding: 10px;
87
+ background-color: #333; /* Dark background */
88
  border-top: 1px solid #ddd;
89
  }
90
  #chat-box {
91
  height: calc(100vh - 100px); /* Adjust the height of chat history */
92
  overflow-y: scroll;
93
  }
94
+ #user-input, #send-btn {
95
+ background-color: #333; /* Keep dark gray background */
96
+ }
97
  """
98
 
99
  return demo