heffnt commited on
Commit
e872704
·
1 Parent(s): a050b4b

Revert to chatInterface

Browse files
Files changed (1) hide show
  1. app.py +12 -34
app.py CHANGED
@@ -150,40 +150,18 @@ with gr.Blocks(css=fancy_css) as demo:
150
  type="messages",
151
  avatar_images=(str(ASSETS_DIR / "monster_icon.png"), str(ASSETS_DIR / "smart_confidant_icon.png"))
152
  )
153
-
154
- # Message input textbox
155
- msg = gr.Textbox(placeholder="Type your message here...", label="Message")
156
-
157
- # Additional inputs in accordion below chatbot
158
- with gr.Accordion("Advanced Settings", open=False):
159
- system_message = gr.Textbox(value=DEFAULT_SYSTEM_MESSAGE, label="System message")
160
- max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
161
- temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
162
- top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
163
- selected_model = gr.Radio(choices=MODEL_OPTIONS, label="Select Model", value=MODEL_OPTIONS[1])
164
-
165
- # Handle message submission
166
- def handle_message(message, history, sys_msg, max_tok, temp, top_p_val, model):
167
- if message.strip():
168
- # For this simplified version, we'll use None for hf_token
169
- # The respond function will handle the case where token is None
170
- hf_token = None
171
-
172
- # Add user message to history
173
- history.append({"role": "user", "content": message})
174
- # Generate response
175
- response_gen = respond(message, history[:-1], sys_msg, max_tok, temp, top_p_val, hf_token, model)
176
- response = ""
177
- for partial_response in response_gen:
178
- response = partial_response
179
- # Add assistant response to history
180
- history.append({"role": "assistant", "content": response})
181
- return "", history
182
-
183
- msg.submit(
184
- handle_message,
185
- inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, selected_model],
186
- outputs=[msg, chatbot]
187
  )
188
 
189
  if __name__ == "__main__":
 
150
  type="messages",
151
  avatar_images=(str(ASSETS_DIR / "monster_icon.png"), str(ASSETS_DIR / "smart_confidant_icon.png"))
152
  )
153
+ # Create ChatInterface with the custom chatbot and additional inputs in accordion below
154
+ gr.ChatInterface(
155
+ fn=respond,
156
+ chatbot=chatbot,
157
+ additional_inputs=[
158
+ gr.Textbox(value=DEFAULT_SYSTEM_MESSAGE, label="System message"),
159
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
160
+ gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
161
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
162
+ gr.Radio(choices=MODEL_OPTIONS, label="Select Model", value=MODEL_OPTIONS[2]),
163
+ ],
164
+ type="messages",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  )
166
 
167
  if __name__ == "__main__":