ombhojane's picture
Create app.py
b7f0e1f verified
raw
history blame
3.74 kB
import streamlit as st
from pathlib import Path
import google.generativeai as genai
import tempfile
# Function to configure and use the google.generativeai model
def analyze_plant_disease(image_bytes):
genai.configure(api_key="AIzaSyAVpLXDazfH6mSlo-CfMzQ4nq5YOnqEA9A")
generation_config = {
"temperature": 0.4,
"top_p": 1,
"top_k": 32,
"max_output_tokens": 4096,
}
safety_settings = [
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
]
model = genai.GenerativeModel(model_name="gemini-1.0-pro-vision-latest",
generation_config=generation_config,
safety_settings=safety_settings)
image_parts = [{"mime_type": "image/jpeg", "data": image_bytes}]
prompt_parts = [
"""
You are a professional vacant space detection in maps expert. I have provided an image of a city. Please analyze the image and provide the following information:
Identify all possibilities of vacant spaces in the city that could potentially be converted into green spaces.
Select the best vacant space and provide the following detail:
Location details (name of the area, neighborhood, etc.)
Geocoordinates (latitude and longitude)
Justify your selection as the best choice, considering factors such as population density, accessibility, and any other relevant criteria.
give this in 3 bullet points, e.g. response format:
- Location: details here
- Geocoordinates: details here
- Justification: details here
Based on the selected best vacant space, provide the following details:
a. Accessibility to this green space:
Divide the city into different regions.
For each region, give the region name along suggest the best and most convenient travel accommodations for people to reach the green space from each region (e.g., public transportation routes, walking paths, cycling routes, etc.).
give all in bullet points, e.g. response format
- Region/landmark name: Response here
b. Proposed infrastructure for the green space:
Recommend the type of infrastructure to be built on this vacant space to transform it into a green space.
Consider the geographical conditions, climate, and any other applicable features present in the area when making your recommendations.
Please provide your analysis and recommendations in a structured and organized manner, addressing each section thoroughly.
Note this will be printed in streamlit app, so give proper formatting, have heading, bullet points etc. that syntax is supported in streamlit
""",
image_parts[0],
]
response = model.generate_content(prompt_parts)
return response.text
# Streamlit application starts here
st.title("Vacant Space Detection in Maps using Vision Techniques")
st.write("""
Discover vacant spaces in maps made easy with Vision techniques! Our project uses new age technology to spot vacant spaces in cities through pictures. It's like having a city planner with large data in your pocket! Early detection, simple solutions. Keep your city green!
""")
uploaded_image = st.file_uploader("Choose an image of vacant space", type=["jpeg", "jpg", "png"])
if uploaded_image is not None:
with st.spinner('Analyzing the image...'):
# Read the image and convert to bytes
image_bytes = uploaded_image.getvalue()
result = analyze_plant_disease(image_bytes)
print(result)
st.write(result)