File size: 1,528 Bytes
fdc1d54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5678d
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
import os
import gradio as gr
from phi.agent import Agent
from phi.model.google import Gemini
from google.generativeai import configure


# 🛡 *⿡ API Key Configuration*
os.environ["GOOGLE_API_KEY"] = "AIzaSyCPe2zWISCI11xp9Gyvl9-Q0RJvxbRaL_Y"  # Replace with your API key
configure()

# 🤖 *⿢ Initialize the Image Classification Agent*
agent = Agent(model=Gemini(id="gemini-2.0-flash-exp"), markdown=True)

# 🖼 *⿣ Image Classification Function*
def classify_image(image_file):
    try:
        if image_file is None:
            return "❌ Please upload an image file."

        query = """
        Image: Describe the scene and its significance in this stock image. should i buy or not
        """

        response = agent.run(query, images=[image_file])

        # Handle the response properly
        if hasattr(response, 'content'):
            return response.content  # Correct way to access the result
        else:
            return "❌ Unexpected response format from the agent."

    except Exception as e:
        return f"❌ Error: {str(e)}"

# 🖥 *⿤ Gradio Interface*
iface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(label="📸 Upload Image File", type="filepath"),
    outputs=gr.Textbox(label="📝 Image Classification Result"),
    title="🧠 Image Classification with Gemini",
    description="Upload an image and receive a detailed classification and analysis using AI.",
)

# 🚀 *⿥ Launch the GUI*
if __name__ == "__main__":
    iface.launch(debug=True,share=True)