File size: 984 Bytes
f294fad
 
 
 
 
 
 
 
 
 
42675a0
f294fad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcb5737
f294fad
 
 
 
 
 
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 predict_rat(image):
    """Predict if the uploaded image contains a rat using Google Gemini Pro Vision API."""
    
    model = genai.GenerativeModel("learnlm-2.0-flash-experimental")

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

    # Generate prediction
    response = model.generate_content(
        [img, "Is this an image of a rat? Answer with 'Yes' or 'No' and provide a brief explanation."]
    )
    
    # Extract prediction and explanation
    result = response.text
    return result

# Gradio UI
iface = gr.Interface(
    fn=predict_rat,
    inputs=gr.Image(type="filepath"),
    outputs="text",
    title="Rodent Detection App",
    description="Upload an image to check if it contains a rat."
)

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