Felipe Meres
Fix Gradio TypeError and HF Spaces compatibility
9a8f848
"""
Configuration settings for Florence-2 Document & Image Analyzer
"""
# Model configuration
FLORENCE_MODEL_ID = "microsoft/Florence-2-large"
# Alternative models (comment/uncomment as needed)
# FLORENCE_MODEL_ID = "microsoft/Florence-2-base" # Smaller, faster model
# Processing configuration
MAX_PDF_PAGES = 20 # Maximum number of PDF pages to process
PDF_DPI = 200 # DPI for PDF to image conversion
MAX_IMAGE_SIZE = (1920, 1920) # Maximum image dimensions
# Gradio configuration
GRADIO_THEME = "soft" # Options: default, soft, monochrome, etc.
SHARE_LINK = False # Create public share link
SERVER_PORT = 7860 # Default Gradio port
# Device configuration
FORCE_CPU = False # Set to True to force CPU usage even if GPU available
# Visualization configuration
BBOX_COLORS = ["red", "blue", "green", "orange", "purple", "yellow", "pink", "cyan"]
BBOX_WIDTH = 2
FONT_SIZE = 12
# Task configurations
FLORENCE_TASKS = {
"detailed_caption": {
"prompt": "<MORE_DETAILED_CAPTION>",
"description": "Generate detailed descriptions of the image content",
"max_tokens": 1024
},
"object_detection": {
"prompt": "<OD>",
"description": "Detect and locate objects with bounding boxes",
"max_tokens": 512
},
"dense_captioning": {
"prompt": "<DENSE_REGION_CAPTION>",
"description": "Provide captions for different regions in the image",
"max_tokens": 1024
},
"ocr": {
"prompt": "<OCR>",
"description": "Extract and locate text in the image",
"max_tokens": 512
},
"region_proposal": {
"prompt": "<REGION_PROPOSAL>",
"description": "Identify interesting regions in the image",
"max_tokens": 256
}
}
# Error messages
ERROR_MESSAGES = {
"model_not_loaded": "Florence-2 model is not available. Please check your internet connection and try again.",
"unsupported_format": "Unsupported file format. Please upload PNG, JPG, JPEG, or PDF files.",
"pdf_too_large": f"PDF has too many pages (max: {MAX_PDF_PAGES}). Please use a smaller document.",
"processing_failed": "Failed to process the file. Please try again with a different image.",
"no_file": "Please upload a file first.",
}