Upload 4 files
Browse filesFiles changed (4)
- .gitattributes+2-35
- api.txtAdded+1
- app.pyAdded+101
- requirements.txtAdded+3
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text12# Auto detect text files and perform LF normalization* text=auto
1GOOGLE_API_KEY="AIzaSyDGsO9HM1KDZ0BdZ1RGWP8lC2XR4A_Oz5w"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101import google.generativeai as genaifrom pathlib import Pathimport gradio as grfrom dotenv import load_dotenvimport os
# Load environment variables from a .env fileload_dotenv()
# Configure the GenerativeAI API key using the loaded environment variablegenai.configure(api_key=os.getenv("AIzaSyDGsO9HM1KDZ0BdZ1RGWP8lC2XR4A_Oz5w"))
# Set up the model configuration for text generationgeneration_config = { "temperature": 0.4, "top_p": 1, "top_k": 32, "max_output_tokens": 4096,}
# Define safety settings for content generationsafety_settings = [ {"category": f"HARM_CATEGORY_{category}", "threshold": "BLOCK_MEDIUM_AND_ABOVE"} for category in ["HARASSMENT", "HATE_SPEECH", "SEXUALLY_EXPLICIT", "DANGEROUS_CONTENT"]]
# Initialize the GenerativeModel with the specified model name, configuration, and safety settingsmodel = genai.GenerativeModel( model_name="gemini-pro-vision", generation_config=generation_config, safety_settings=safety_settings,)# Function to read image data from a file path
def read_image_data(file_path): image_path = Path(file_path) if not image_path.exists(): raise FileNotFoundError(f"Could not find image: {image_path}") return {"mime_type": "image/jpeg", "data": image_path.read_bytes()}
# Function to generate a response based on a prompt and an image path
def generate_gemini_response(prompt, image_path): image_data = read_image_data(image_path) response = model.generate_content([prompt, image_data]) return response.text
# Initial input prompt for the plant pathologistinput_prompt = """As a highly skilled plant pathologist, your expertise is indispensable in our pursuit of maintaining optimal plant health. You will be provided with information or samples related to plant diseases, and your role involves conducting a detailed analysis to identify the specific issues, propose solutions, and offer recommendations.
**Analysis Guidelines:**
1. **Disease Identification:** Examine the provided information or samples to identify and characterize plant diseases accurately.
2. **Detailed Findings:** Provide in-depth findings on the nature and extent of the identified plant diseases, including affected plant parts, symptoms, and potential causes.
3. **Next Steps:** Outline the recommended course of action for managing and controlling the identified plant diseases. This may involve treatment options, preventive measures, or further investigations.
4. **Recommendations:** Offer informed recommendations for maintaining plant health, preventing disease spread, and optimizing overall plant well-being.
5. **Important Note:** As a plant pathologist, your insights are vital for informed decision-making in agriculture and plant management. Your response should be thorough, concise, and focused on plant health.
**Disclaimer:***"Please note that the information provided is based on plant pathology analysis and should not replace professional agricultural advice. Consult with qualified agricultural experts before implementing any strategies or treatments."*
Your role is pivotal in ensuring the health and productivity of plants. Proceed to analyze the provided information or samples, adhering to the structured """
# Function to process uploaded files and generate a response
def process_uploaded_files(files): file_path = files[0].name if files else None response = generate_gemini_response( input_prompt, file_path) if file_path else None return file_path, response
# Gradio interface setupwith gr.Blocks() as demo: file_output = gr.Textbox() image_output = gr.Image() combined_output = [image_output, file_output]
# Upload button for user to provide images upload_button = gr.UploadButton( "Click to Upload an Image", file_types=["image"], file_count="multiple", ) # Set up the upload button to trigger the processing function upload_button.upload(process_uploaded_files, upload_button, combined_output)
# Launch the Gradio interface with debug mode enableddemo.launch(debug=True)123gradiogoogle-generativeaipython-dotenv.gitattributes+2-35
api.txtAdded+1
app.pyAdded+101
requirements.txtAdded+3