Spaces:
Runtime error
Runtime error
change in app to redirect to dashboard
Browse files
app.py
CHANGED
|
@@ -106,45 +106,63 @@ def load_personas():
|
|
| 106 |
return st.session_state.personas
|
| 107 |
|
| 108 |
|
| 109 |
-
def
|
| 110 |
-
st.
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
with st.form("persona_form"):
|
| 113 |
-
name = st.text_input("Character Name")
|
| 114 |
-
mode = st.selectbox("Mode", ["auto", "custom"])
|
| 115 |
-
tone = st.text_input("Tone (optional)")
|
| 116 |
-
summary = st.text_area("Summary (required only for CUSTOM)") if mode == "custom" else None
|
| 117 |
-
submit = st.form_submit_button("Create")
|
| 118 |
-
|
| 119 |
-
if submit:
|
| 120 |
-
if not name:
|
| 121 |
-
st.error("Character name is required")
|
| 122 |
-
return
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
"mode": mode,
|
| 132 |
-
"tone": tone or None,
|
| 133 |
-
"summary": summary or None,
|
| 134 |
-
}
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
st.success(f"🎉 Character **{new_p['character_name']}** created successfully!")
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
else:
|
| 147 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
def delete_persona(persona_id):
|
|
@@ -243,11 +261,8 @@ def main():
|
|
| 243 |
f"### {p['character_name']}\nMode: `{p['mode']}`\nTone: `{p.get('tone', '')}`"
|
| 244 |
)
|
| 245 |
|
| 246 |
-
if cols[1].button("Chat", key=f"chat_{p['id']}"):
|
| 247 |
-
|
| 248 |
-
st.session_state.persona_name = p["character_name"]
|
| 249 |
-
st.session_state.menu = "Chat"
|
| 250 |
-
st.rerun()
|
| 251 |
|
| 252 |
if cols[2].button("Delete", key=f"del_{p['id']}"):
|
| 253 |
delete_persona(p["id"])
|
|
|
|
| 106 |
return st.session_state.personas
|
| 107 |
|
| 108 |
|
| 109 |
+
def go_to_chat(p_id, p_name):
|
| 110 |
+
st.session_state.persona_id = p_id
|
| 111 |
+
st.session_state.persona_name = p_name
|
| 112 |
+
st.session_state.menu = "Chat"
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
def handle_create_persona():
|
| 116 |
+
name = st.session_state.cp_name
|
| 117 |
+
mode = st.session_state.cp_mode
|
| 118 |
+
tone = st.session_state.cp_tone
|
| 119 |
+
summary = st.session_state.cp_summary
|
| 120 |
|
| 121 |
+
if not name:
|
| 122 |
+
st.session_state.cp_msg = ("error", "Character name is required")
|
| 123 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
if mode == "custom" and not summary:
|
| 126 |
+
st.session_state.cp_msg = ("error", "Summary required for custom mode")
|
| 127 |
+
return
|
|
|
|
| 128 |
|
| 129 |
+
payload = {
|
| 130 |
+
"user_id": st.session_state.user_id,
|
| 131 |
+
"character_name": name,
|
| 132 |
+
"mode": mode,
|
| 133 |
+
"tone": tone or None,
|
| 134 |
+
"summary": summary or None,
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
r = api_post("/personas", json=payload)
|
| 138 |
+
if r and r.status_code == 200:
|
| 139 |
+
new_p = r.json()
|
| 140 |
+
# Success - navigate to chat
|
| 141 |
+
st.session_state.persona_id = new_p["id"]
|
| 142 |
+
st.session_state.persona_name = new_p["character_name"]
|
| 143 |
+
st.session_state.menu = "Chat"
|
| 144 |
+
st.session_state.cp_msg = None # Clear message
|
| 145 |
+
else:
|
| 146 |
+
st.session_state.cp_msg = ("error", r.text if r else "Error")
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def create_persona_ui():
|
| 150 |
+
st.header("Create Persona")
|
| 151 |
+
|
| 152 |
+
if "cp_msg" in st.session_state and st.session_state.cp_msg:
|
| 153 |
+
type_, msg = st.session_state.cp_msg
|
| 154 |
+
if type_ == "error":
|
| 155 |
+
st.error(msg)
|
| 156 |
else:
|
| 157 |
+
st.success(msg)
|
| 158 |
+
|
| 159 |
+
with st.form("persona_form"):
|
| 160 |
+
st.text_input("Character Name", key="cp_name")
|
| 161 |
+
st.selectbox("Mode", ["auto", "custom"], key="cp_mode")
|
| 162 |
+
st.text_input("Tone (optional)", key="cp_tone")
|
| 163 |
+
st.text_area("Summary (required only for CUSTOM)", key="cp_summary")
|
| 164 |
+
|
| 165 |
+
st.form_submit_button("Create", on_click=handle_create_persona)
|
| 166 |
|
| 167 |
|
| 168 |
def delete_persona(persona_id):
|
|
|
|
| 261 |
f"### {p['character_name']}\nMode: `{p['mode']}`\nTone: `{p.get('tone', '')}`"
|
| 262 |
)
|
| 263 |
|
| 264 |
+
if cols[1].button("Chat", key=f"chat_{p['id']}", on_click=go_to_chat, args=(p['id'], p['character_name'])):
|
| 265 |
+
pass
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
if cols[2].button("Delete", key=f"del_{p['id']}"):
|
| 268 |
delete_persona(p["id"])
|