| | |
| | """ |
| | Vision AI - Detailed Image Analysis |
| | """ |
| |
|
| | import gradio as gr |
| | from transformers import pipeline |
| | from PIL import Image |
| |
|
| | print("Loading vision model...") |
| |
|
| | |
| | vision_pipeline = pipeline( |
| | "image-to-text", |
| | model="Salesforce/blip-image-captioning-large", |
| | device=-1 |
| | ) |
| |
|
| | 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)) |
| | |
| | |
| | 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)}" |
| |
|
| | |
| | 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 |
| | ) |
| |
|