File size: 929 Bytes
55f0a1e
c955125
55f0a1e
c955125
55f0a1e
 
c415692
c955125
55f0a1e
3c6c0fd
46068de
55f0a1e
 
 
410478b
55f0a1e
 
 
 
 
 
 
97e1f50
 
 
 
 
 
 
bd501fa
d2f5f4b
97e1f50
 
 
 
 
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
import google.generativeai as genai
import gradio as gr
from PIL import Image

# Set up Gemini API key
genai.configure(api_key="AIzaSyDnx_qUjGTFG1pv1otPUhNt_bGGv14aMDI")  # Replace with your API key

def generate_caption(image):
    """Generate a caption for the uploaded image using Google Gemini Pro Vision API."""

    model = genai.GenerativeModel("gemini-1.5-flash")

    # Open image using PIL
    img = Image.open(image)

    # Generate caption
    response = model.generate_content(
        [img, "Describe the contents of this image in detail."]
    )
    
    # Extract caption
    caption = response.text
    return caption

# Gradio UI
iface = gr.Interface(
    fn=generate_caption,
    inputs=gr.Image(type="filepath"),
    outputs="text",
    title="Image Captioning App",
    description="Upload an image, and a descriptive caption will be generated."
)

# Run the app
if __name__ == "__main__":
    iface.launch()