Spaces:
Sleeping
Sleeping
File size: 1,737 Bytes
60a1c01 f46fcee 60a1c01 9753d3c 04598bf 9753d3c 60a1c01 1191499 60a1c01 |
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 49 50 51 52 53 54 55 |
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()
|