Spaces:
Running
Running
Update slide deck generator when a different model is selected in the UI
Browse files
app.py
CHANGED
|
@@ -224,6 +224,16 @@ with st.sidebar:
|
|
| 224 |
' Ollama-compatible and supported GPU is strongly recommended.'
|
| 225 |
)
|
| 226 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
api_key_token: str = ''
|
| 228 |
azure_endpoint: str = ''
|
| 229 |
azure_deployment: str = ''
|
|
@@ -261,7 +271,7 @@ with st.sidebar:
|
|
| 261 |
st.stop()
|
| 262 |
|
| 263 |
env_key_name = GlobalConfig.PROVIDER_ENV_KEYS.get(selected_provider)
|
| 264 |
-
default_api_key = os.getenv(env_key_name,
|
| 265 |
|
| 266 |
# Always sync session state to env value if needed (autofill on provider change)
|
| 267 |
if default_api_key and st.session_state.get(API_INPUT_KEY, None) != default_api_key:
|
|
@@ -277,6 +287,15 @@ with st.sidebar:
|
|
| 277 |
disabled=bool(default_api_key),
|
| 278 |
)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
# Additional configs for Azure OpenAI
|
| 281 |
with st.expander('**Azure OpenAI-specific configurations**'):
|
| 282 |
azure_endpoint = st.text_input(
|
|
|
|
| 224 |
' Ollama-compatible and supported GPU is strongly recommended.'
|
| 225 |
)
|
| 226 |
)
|
| 227 |
+
# If a SlideDeckAI instance already exists in session state, update its model
|
| 228 |
+
# to reflect the user change rather than reusing the old model
|
| 229 |
+
# No API key required for local models
|
| 230 |
+
if SLIDE_GENERATOR in st.session_state and llm_provider_to_use:
|
| 231 |
+
try:
|
| 232 |
+
st.session_state[SLIDE_GENERATOR].set_model(llm_provider_to_use)
|
| 233 |
+
except Exception as e:
|
| 234 |
+
logger.exception('Failed to update model on existing SlideDeckAI: %s', e)
|
| 235 |
+
# If updating fails, drop the stored instance so a new one is created
|
| 236 |
+
st.session_state.pop(SLIDE_GENERATOR, None)
|
| 237 |
api_key_token: str = ''
|
| 238 |
azure_endpoint: str = ''
|
| 239 |
azure_deployment: str = ''
|
|
|
|
| 271 |
st.stop()
|
| 272 |
|
| 273 |
env_key_name = GlobalConfig.PROVIDER_ENV_KEYS.get(selected_provider)
|
| 274 |
+
default_api_key = os.getenv(env_key_name, '') if env_key_name else ''
|
| 275 |
|
| 276 |
# Always sync session state to env value if needed (autofill on provider change)
|
| 277 |
if default_api_key and st.session_state.get(API_INPUT_KEY, None) != default_api_key:
|
|
|
|
| 287 |
disabled=bool(default_api_key),
|
| 288 |
)
|
| 289 |
|
| 290 |
+
# If a model was updated in the sidebar, make sure to update it in the SlideDeckAI instance
|
| 291 |
+
if SLIDE_GENERATOR in st.session_state and llm_provider_to_use:
|
| 292 |
+
try:
|
| 293 |
+
st.session_state[SLIDE_GENERATOR].set_model(llm_provider_to_use, api_key_token)
|
| 294 |
+
except Exception as e:
|
| 295 |
+
logger.exception('Failed to update model on existing SlideDeckAI: %s', e)
|
| 296 |
+
# If updating fails, drop the stored instance so a new one is created
|
| 297 |
+
st.session_state.pop(SLIDE_GENERATOR, None)
|
| 298 |
+
|
| 299 |
# Additional configs for Azure OpenAI
|
| 300 |
with st.expander('**Azure OpenAI-specific configurations**'):
|
| 301 |
azure_endpoint = st.text_input(
|