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)