File size: 2,253 Bytes
20e8d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9a8f848
20e8d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
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.",
}