Added the ability for users to select an image generation model from a dropdown list. The selected model is persisted using the browser's localStorage and automatically restored on subsequent visits.
- Existing
/modelsendpoint (lines 34-82): Already implemented to fetch available models from Ollama API and filter them based onIMAGE_GEN_MODEL_LIST - Added
/test.htmlroute (lines 34-46): Serves a test page for verifying the model selection functionality
Added comprehensive styling for the <select> element:
- Custom dropdown with gradient border on focus
- Custom SVG arrow icon (embedded as data URI)
- Dark theme styling for options
- Smooth transitions and hover effects
- Consistent with existing design system
Added a new form group before the prompt input:
<div class="form-group">
<label for="modelSelect">Select Model</label>
<select id="modelSelect" required>
<option value="">Loading models...</option>
</select>
</div>Constants and Variables:
MODEL_STORAGE_KEY = 'ollama_selected_model'- localStorage key for persisting model selection
loadModels() Function:
- Fetches available models from
/modelsAPI endpoint - Populates the dropdown with available models
- Loads previously selected model from localStorage
- Falls back to first model if no saved preference exists
- Handles errors gracefully with user-friendly messages
Event Listener:
- Saves selected model to localStorage whenever the user changes the selection
Integration:
- Modified the image generation request (line 783) to use
modelSelect.valueinstead of hardcoded model name
- Page loads and
loadModels()is called automatically - Function fetches models from
/modelsAPI endpoint - Dropdown is populated with available models
- If a model was previously selected (stored in localStorage), it's automatically selected
- Otherwise, the first available model is selected by default
- User selects a model from the dropdown
- Selection is immediately saved to localStorage via the change event listener
- When user generates an image, the selected model is used in the API request
- Model selection is stored in browser's localStorage with key
'ollama_selected_model' - Persists across browser sessions
- Automatically restored when user revisits the page
- Scoped to the domain (localhost:8080)
Response: JSON array of available model names
["x/z-image-turbo:bf16", "x/flux2-klein"]Example:
curl http://localhost:8080/modelsA test page (test.html) has been created to verify the implementation:
- Access at:
http://localhost:8080/test.html - Tests include:
- API endpoint verification
- localStorage save/load/clear operations
- Full integration test with dropdown population
/Users/nick/AntigravityProjects/OllamaImageGenerator/index.html- Added model selection UI and logic/Users/nick/AntigravityProjects/OllamaImageGenerator/server.py- Added test.html route/Users/nick/AntigravityProjects/OllamaImageGenerator/README.md- Updated documentation
/Users/nick/AntigravityProjects/OllamaImageGenerator/test.html- Test page for verification
- Uses standard Web Storage API (localStorage)
- Compatible with all modern browsers (Chrome, Firefox, Safari, Edge)
- Gracefully handles cases where localStorage is unavailable
- API fetch errors are caught and displayed to the user
- Empty model list is handled with appropriate message
- Invalid saved model (not in current list) falls back to first available model
- Console logging for debugging purposes