Spaces:
Running
Running
Anirudh Esthuri
commited on
Commit
·
f827eab
1
Parent(s):
7d97a41
Add Hugging Face user ID support for automatic persona assignment
Browse files
app.py
CHANGED
|
@@ -354,14 +354,25 @@ with st.sidebar:
|
|
| 354 |
set_model(model_id)
|
| 355 |
|
| 356 |
st.markdown("#### Choose user persona")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
selected_persona = st.selectbox(
|
| 358 |
"Choose user persona",
|
| 359 |
["Charlie", "Jing", "Charles", "Control"],
|
| 360 |
label_visibility="collapsed",
|
| 361 |
)
|
| 362 |
-
custom_persona = st.text_input("Or enter your name", "")
|
| 363 |
persona_name = (
|
| 364 |
-
custom_persona.strip() if custom_persona.strip() else selected_persona
|
| 365 |
)
|
| 366 |
|
| 367 |
compare_personas = st.checkbox("Compare with Control persona")
|
|
|
|
| 354 |
set_model(model_id)
|
| 355 |
|
| 356 |
st.markdown("#### Choose user persona")
|
| 357 |
+
|
| 358 |
+
# Get Hugging Face user ID if available (in HF Spaces)
|
| 359 |
+
hf_user_id = os.getenv("SPACE_USER") or os.getenv("HF_USERNAME")
|
| 360 |
+
|
| 361 |
+
if hf_user_id:
|
| 362 |
+
# Use HF user ID as default, but allow override
|
| 363 |
+
st.info(f"👤 Signed in as: **{hf_user_id}**")
|
| 364 |
+
default_persona = hf_user_id
|
| 365 |
+
else:
|
| 366 |
+
default_persona = "Charlie"
|
| 367 |
+
|
| 368 |
selected_persona = st.selectbox(
|
| 369 |
"Choose user persona",
|
| 370 |
["Charlie", "Jing", "Charles", "Control"],
|
| 371 |
label_visibility="collapsed",
|
| 372 |
)
|
| 373 |
+
custom_persona = st.text_input("Or enter your name", default_persona if hf_user_id else "")
|
| 374 |
persona_name = (
|
| 375 |
+
custom_persona.strip() if custom_persona.strip() else (hf_user_id if hf_user_id else selected_persona)
|
| 376 |
)
|
| 377 |
|
| 378 |
compare_personas = st.checkbox("Compare with Control persona")
|