File size: 2,065 Bytes
6eaa671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""
Vision AI - Detailed Image Analysis
"""

import gradio as gr
from transformers import pipeline
from PIL import Image

print("Loading vision model...")

# Advanced captioning model for detailed descriptions
vision_pipeline = pipeline(
    "image-to-text",
    model="Salesforce/blip-image-captioning-large",
    device=-1  # CPU
)

print("✓ Model loaded!")

def analyze_image_detailed(image, prompt=""):
    """Analyze image with detailed captioning"""
    if image is None:
        return "Please upload an image first"
    
    try:
        if isinstance(image, str):
            image = Image.open(image)
        
        image.thumbnail((512, 512))
        
        # Generate detailed caption
        result = vision_pipeline(image)
        caption = result[0]["generated_text"] if result else "No output"
        
        return caption
    except Exception as e:
        return f"Error: {str(e)}"

# Create Gradio interface
with gr.Blocks(title="Vision AI - Detailed Analysis", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
    # 🖼️ Vision AI - Advanced Image Analysis
    
    Get detailed analysis of your images using advanced AI.
    
    - **Model**: BLIP Large (Salesforce) 
    - **Processing**: 100% local (no cloud)
    - **Analysis**: Comprehensive image descriptions
    """)
    
    with gr.Row():
        with gr.Column():
            gr.Markdown("### Upload Image")
            image_input = gr.Image(label="Select Image", type="pil")
            analyze_btn = gr.Button("🔍 Analyze Image", size="lg", variant="primary")
        
        with gr.Column():
            gr.Markdown("### Detailed Analysis")
            output = gr.Textbox(
                label="Image Description",
                lines=8,
                interactive=False
            )
    
    analyze_btn.click(
        fn=analyze_image_detailed,
        inputs=image_input,
        outputs=output
    )

if __name__ == "__main__":
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=True
    )