ZennyKenny commited on
Commit
02a184a
·
verified ·
1 Parent(s): aefc9b8

update messaging format + disable queue

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -37,19 +37,21 @@ TEMPERATURE = 0.8 # Balanced between creativity and focus
37
  TOP_P = 0.9 # Allows for some diversity while staying on topic
38
 
39
  @spaces.GPU
40
- def respond(message, history: list[tuple[str, str]]):
41
  messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
42
 
43
- for val in history:
44
- if val[0]:
45
- messages.append({"role": "user", "content": val[0]})
46
- if val[1]:
47
- messages.append({"role": "assistant", "content": val[1]})
48
 
 
49
  messages.append({"role": "user", "content": message})
50
 
51
  response = ""
52
 
 
53
  for message in client.chat_completion(
54
  messages,
55
  max_tokens=MAX_TOKENS,
@@ -58,13 +60,14 @@ def respond(message, history: list[tuple[str, str]]):
58
  top_p=TOP_P,
59
  ):
60
  token = message.choices[0].delta.content
61
-
62
  response += token
63
  yield response
64
 
 
65
  custom_css = """
66
  body {
67
  background-color: #f9d029 !important;
 
68
  .chatbot {
69
  background-color: #000000 !important;
70
  color: #ffffff !important;
@@ -96,13 +99,15 @@ footer {
96
  }
97
  """
98
 
99
- montebello = gr.ChatInterface(
100
- respond,
101
- title="montebello.ai",
102
- textbox=gr.Textbox(placeholder="How can montebello.ai help you leverage AI in your small business?", container=False, scale=7),
103
- submit_btn=gr.Button("Send", variant="primary"),
104
- css=custom_css
105
- )
 
 
106
 
107
  if __name__ == "__main__":
108
- montebello.launch(queue=False)
 
37
  TOP_P = 0.9 # Allows for some diversity while staying on topic
38
 
39
  @spaces.GPU
40
+ def respond(message, history):
41
  messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
42
 
43
+ # Add chat history to messages
44
+ for user_msg, bot_msg in history:
45
+ messages.append({"role": "user", "content": user_msg})
46
+ if bot_msg:
47
+ messages.append({"role": "assistant", "content": bot_msg})
48
 
49
+ # Add the latest user message
50
  messages.append({"role": "user", "content": message})
51
 
52
  response = ""
53
 
54
+ # Stream the response
55
  for message in client.chat_completion(
56
  messages,
57
  max_tokens=MAX_TOKENS,
 
60
  top_p=TOP_P,
61
  ):
62
  token = message.choices[0].delta.content
 
63
  response += token
64
  yield response
65
 
66
+ # Custom CSS for the interface
67
  custom_css = """
68
  body {
69
  background-color: #f9d029 !important;
70
+ }
71
  .chatbot {
72
  background-color: #000000 !important;
73
  color: #ffffff !important;
 
99
  }
100
  """
101
 
102
+ # Create the ChatInterface with customizations
103
+ with gr.Blocks(enable_queue=False, css=custom_css) as montebello:
104
+ gr.Markdown("# montebello.ai")
105
+ chatbot = gr.Chatbot(height=500)
106
+ textbox = gr.Textbox(placeholder="How can montebello.ai help you leverage AI in your small business?", container=False, scale=7)
107
+ submit_btn = gr.Button("Send", variant="primary")
108
+
109
+ # Define the chat interface
110
+ submit_btn.click(respond, [textbox, chatbot], [textbox, chatbot])
111
 
112
  if __name__ == "__main__":
113
+ montebello.launch()