import os from io import BytesIO import gradio as gr import google.generativeai as genai from PIL import Image from dotenv import load_dotenv # Load environment variables load_dotenv() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) input_prompt=""" Analyze the image and predict type of soil " "1. Soil Type: Sandy/Clayey/Loamy," "2. ", """ # Function to get a response from the Google Gemini Vision API def get_gemini_response(image): model = genai.GenerativeModel('gemini-1.5-pro') # Convert PIL image to bytes bytes_io = BytesIO() image.save(bytes_io, format='PNG') bytes_data = bytes_io.getvalue() response=model.generate_content([input_prompt,image]) # Placeholder logic for now: replace with actual API usage # You would pass the image bytes data to the API # Currently this is a mock response crop_name = "Wheat" # Example: Replace this with the actual API result disease_type = "Wheat Septoria" # Example: Replace this with the actual API result # Return disease info #return get_disease_info(crop_name, disease_type) return response.text # Function to handle the uploaded image and predict crop health def predict_crop_health(uploaded_image): # Pass the image to the Gemini API to get prediction return get_gemini_response(uploaded_image) # Define the Gradio interface: Inputs and Outputs inputs = gr.Image(type="pil", label="Upload Crop Image") outputs = gr.Markdown(label="Prediction Results") # Launch the Gradio interface gr.Interface( fn=predict_crop_health, inputs=inputs, outputs=gr.Textbox(label="Crop Disease Predictor"), title="Soil Type Classifier", description="Upload The Image Of Soil", live=False ).launch()