ombhojane commited on
Commit
b7f0e1f
1 Parent(s): 011b396

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pathlib import Path
3
+ import google.generativeai as genai
4
+ import tempfile
5
+
6
+ # Function to configure and use the google.generativeai model
7
+ def analyze_plant_disease(image_bytes):
8
+ genai.configure(api_key="AIzaSyAVpLXDazfH6mSlo-CfMzQ4nq5YOnqEA9A")
9
+
10
+ generation_config = {
11
+ "temperature": 0.4,
12
+ "top_p": 1,
13
+ "top_k": 32,
14
+ "max_output_tokens": 4096,
15
+ }
16
+
17
+ safety_settings = [
18
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
19
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
20
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
21
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
22
+ ]
23
+
24
+ model = genai.GenerativeModel(model_name="gemini-1.0-pro-vision-latest",
25
+ generation_config=generation_config,
26
+ safety_settings=safety_settings)
27
+
28
+ image_parts = [{"mime_type": "image/jpeg", "data": image_bytes}]
29
+
30
+ prompt_parts = [
31
+ """
32
+ 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:
33
+
34
+ Identify all possibilities of vacant spaces in the city that could potentially be converted into green spaces.
35
+
36
+ Select the best vacant space and provide the following detail:
37
+ Location details (name of the area, neighborhood, etc.)
38
+ Geocoordinates (latitude and longitude)
39
+ Justify your selection as the best choice, considering factors such as population density, accessibility, and any other relevant criteria.
40
+ give this in 3 bullet points, e.g. response format:
41
+ - Location: details here
42
+ - Geocoordinates: details here
43
+ - Justification: details here
44
+
45
+ Based on the selected best vacant space, provide the following details:
46
+ a. Accessibility to this green space:
47
+ Divide the city into different regions.
48
+ 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.).
49
+ give all in bullet points, e.g. response format
50
+ - Region/landmark name: Response here
51
+
52
+
53
+ b. Proposed infrastructure for the green space:
54
+ Recommend the type of infrastructure to be built on this vacant space to transform it into a green space.
55
+ Consider the geographical conditions, climate, and any other applicable features present in the area when making your recommendations.
56
+
57
+ Please provide your analysis and recommendations in a structured and organized manner, addressing each section thoroughly.
58
+ Note this will be printed in streamlit app, so give proper formatting, have heading, bullet points etc. that syntax is supported in streamlit
59
+ """,
60
+ image_parts[0],
61
+ ]
62
+
63
+ response = model.generate_content(prompt_parts)
64
+ return response.text
65
+
66
+ # Streamlit application starts here
67
+ st.title("Vacant Space Detection in Maps using Vision Techniques")
68
+
69
+ st.write("""
70
+ 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!
71
+ """)
72
+
73
+ uploaded_image = st.file_uploader("Choose an image of vacant space", type=["jpeg", "jpg", "png"])
74
+ if uploaded_image is not None:
75
+ with st.spinner('Analyzing the image...'):
76
+ # Read the image and convert to bytes
77
+ image_bytes = uploaded_image.getvalue()
78
+ result = analyze_plant_disease(image_bytes)
79
+ print(result)
80
+ st.write(result)