Spaces:
Configuration error
Configuration error
Revert to chatInterface
Browse files
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 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 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__":
|