Skip to content

Conversation

@cadusp
Copy link

@cadusp cadusp commented Oct 30, 2025

No description provided.

- Created streamlit_ocr_app.py: Complete web application for image OCR
- Features:
  * Image upload support (JPG, PNG, JPEG)
  * Multiple resolution modes (Tiny, Small, Base, Large, Gundam, Custom)
  * Predefined prompts for different OCR tasks
  * Real-time OCR processing with DeepSeek model
  * Result visualization (text, markdown, statistics)
  * Download results as TXT or MD files
  * Advanced settings (test_compress, save_results)
  * Full transforms integration (ImageTransform, dynamic_preprocess, count_tiles)
- Added requirements_streamlit.txt: Dependencies for Streamlit app
- Added STREAMLIT_README.md: Complete documentation with usage examples

All functionality integrated in a single file as requested.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fixes:
- Replace use_container_width with width='stretch' (Streamlit 2025-12-31 deprecation)
  * st.image: use_container_width=True -> width='stretch'
  * st.button: use_container_width=True -> width='stretch'

- Add automatic fallback for flash_attn not installed
  * Try to load with flash_attention_2 first (best performance)
  * Fallback to eager attention if flash_attn not available
  * Show informative messages during model loading
  * Works on both GPU and CPU without flash_attn

Updates:
- requirements_streamlit.txt: Add comments about optional flash-attn
- STREAMLIT_README.md:
  * Add section about Flash Attention 2 installation
  * Add troubleshooting for flash_attn errors
  * Clarify that app works without flash_attn
  * Explain deepseek_vl_v2 warning is not critical

The application now works out of the box without flash-attn installed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changes:
- Force device to CPU regardless of CUDA availability
- Remove GPU/CUDA detection and configuration
- Use torch.float32 instead of torch.bfloat16 for CPU compatibility
- Simplify model loading (no flash_attention_2 needed on CPU)
- Update sidebar to show CPU-only configuration
- Add warning that processing will be slower but functional

This configuration ensures the app runs on CPU-only environments
without requiring CUDA or GPU hardware.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fixes the warning:
"You are using a model of type deepseek_vl_v2 to instantiate a model
of type DeepseekOCR. This is not supported for all configurations of
models and can yield errors."

Changes to streamlit_ocr_app.py:
- Add warnings module import
- Filter warnings for deepseek_vl_v2 and DeepseekOCR type mismatch
- Set TRANSFORMERS_VERBOSITY to 'error' to suppress non-critical warnings
- Add new expander section "⚠️ Notas Técnicas e Avisos Conhecidos" with:
  * Detailed explanation of the warning
  * Why it happens (config.json vs Python class naming)
  * Why it's safe to ignore (trust_remote_code=True behavior)
  * CPU vs GPU configuration notes
  * Flash Attention 2 optional dependency info

Changes to STREAMLIT_README.md:
- Expand section about deepseek_vl_v2 warning
- Add detailed explanation of why the warning appears
- Clarify that it's informational only and not an error
- Explain trust_remote_code=True behavior
- Note that app automatically suppresses this warning

The warning is expected and harmless when using trust_remote_code=True
with custom model architectures. The model loads and functions perfectly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fixes SafetensorError: "EOF while parsing a value" error that occurs
when HuggingFace cache has corrupted/incomplete model files.

Changes to streamlit_ocr_app.py:
- Add clear_model_cache() helper function to remove corrupted cache
- Enhanced load_model() with multi-stage error recovery:
  1. Try loading with safetensors (normal)
  2. If SafetensorError detected, identify corrupted files
  3. Automatically clear cache and re-download model
  4. Fallback to loading without safetensors if needed
- Add comprehensive error messages with manual recovery instructions
- Show step-by-step instructions for Windows/Linux/Mac
- Include PowerShell commands for Windows cache cleanup
- Add environment variable workarounds (TRANSFORMERS_CACHE, HF_HUB_DISABLE_SYMLINKS)

Changes to STREAMLIT_README.md:
- Add dedicated section for SafetensorError troubleshooting
- Explain causes: interrupted download, connection issues, corrupted cache
- Document automatic recovery process (4 steps)
- Provide manual recovery instructions for all platforms
- Add prevention tips: stable connection, sufficient disk space
- Include cache location paths for Windows/Linux/Mac

Error detection patterns:
- "SafetensorError" in error message
- "EOF while parsing" in error message
- "invalid JSON" in error message

Recovery flow:
1. Detect SafetensorError → Warn user
2. Find cache dirs matching "*deepseek*" → Remove all
3. Force re-download with force_download=True
4. If fails → Fallback to use_safetensors=False

This ensures the app can recover from corrupted downloads automatically
without requiring manual intervention in most cases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fixed error that occurred when trying to display processing configuration.

The variable 'device_info' was removed when we forced CPU usage but was
still being referenced in the config_info dictionary on line 419.

Change:
- Line 419: "Device": device_info → "Device": "CPU (Forçado)"

This hardcoded value is correct since the app is configured to always
use CPU (device = "cpu" on line 101).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Added comprehensive .gitignore to exclude:
- Python cache files (__pycache__/, *.pyc, *.pyo)
- Virtual environments (venv/, env/)
- IDE files (.vscode/, .idea/)
- OS files (.DS_Store, Thumbs.db)
- Build artifacts (dist/, build/, *.egg-info/)
- Jupyter checkpoints
- Streamlit cache

This prevents committing auto-generated files that should not be
in version control.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants