Spaces:
Sleeping
Sleeping
File size: 1,013 Bytes
f294fad ea7855b f294fad 2903d39 3acb186 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 37 |
import google.generativeai as genai
import gradio as gr
from PIL import Image
import os
# Set up Gemini API key
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')
genai.configure(api_key="GEMINI_API_KEY") # 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() |