ombhojane's picture
Update app.py
be096f8 verified
raw
history blame contribute delete
No virus
3.49 kB
import streamlit as st
from pathlib import Path
import google.generativeai as genai
import tempfile
GEMINI_API = st.secrets["GEMINI_API_KEY"]
genai.configure(api_key=GEMINI_API)
# Function to configure and use the google.generativeai model
def analyze_plant_disease(image_bytes):
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"},
]
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
# Part 5: Create the Model
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
)
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.
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.).
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)