ajsbsd commited on
Commit
8993bb7
·
verified ·
1 Parent(s): 3eac2fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -7
app.py CHANGED
@@ -75,7 +75,6 @@ def predict_chat(message: str, history: list):
75
  yield "Error: Model or tokenizer failed to load. Please check the Space logs for details."
76
  return
77
 
78
- # history is already in the 'messages' format if type='messages' is set on chatbot
79
  messages = [{"role": "system", "content": "You are a friendly chatbot."}] + history
80
  messages.append({"role": "user", "content": message})
81
 
@@ -129,18 +128,15 @@ def predict_chat(message: str, history: list):
129
  if __name__ == "__main__":
130
  load_model_for_zerocpu()
131
 
132
- # Initial message for the chatbot in the 'messages' format
133
  initial_messages_for_value = [{"role": "assistant", "content":
134
  "Hello! I'm an AI assistant. I'm currently running in a CPU-only "
135
  "environment for efficient demonstration. How can I help you today?"
136
  }]
137
 
138
- # Define the Chatbot component without initial value in the constructor
139
  chatbot_component = gr.Chatbot(height=500, type='messages')
140
 
141
  demo = gr.ChatInterface(
142
  fn=predict_chat,
143
- # Pass the pre-defined chatbot_component
144
  chatbot=chatbot_component,
145
  textbox=gr.Textbox(
146
  placeholder="Ask me a question...",
@@ -161,11 +157,9 @@ if __name__ == "__main__":
161
  ["What's the best way to stay motivated?"],
162
  ],
163
  cache_examples=False,
164
- clear_btn="Clear Chat"
165
  )
166
 
167
- # NEW LINE: Set the initial value after the demo (ChatInterface) is created
168
- # This specifically targets the internal chatbot component that ChatInterface uses.
169
  demo.chatbot.value = initial_messages_for_value
170
 
171
  demo.launch()
 
75
  yield "Error: Model or tokenizer failed to load. Please check the Space logs for details."
76
  return
77
 
 
78
  messages = [{"role": "system", "content": "You are a friendly chatbot."}] + history
79
  messages.append({"role": "user", "content": message})
80
 
 
128
  if __name__ == "__main__":
129
  load_model_for_zerocpu()
130
 
 
131
  initial_messages_for_value = [{"role": "assistant", "content":
132
  "Hello! I'm an AI assistant. I'm currently running in a CPU-only "
133
  "environment for efficient demonstration. How can I help you today?"
134
  }]
135
 
 
136
  chatbot_component = gr.Chatbot(height=500, type='messages')
137
 
138
  demo = gr.ChatInterface(
139
  fn=predict_chat,
 
140
  chatbot=chatbot_component,
141
  textbox=gr.Textbox(
142
  placeholder="Ask me a question...",
 
157
  ["What's the best way to stay motivated?"],
158
  ],
159
  cache_examples=False,
160
+ # REMOVED: clear_btn="Clear Chat"
161
  )
162
 
 
 
163
  demo.chatbot.value = initial_messages_for_value
164
 
165
  demo.launch()