Skip to content

Commit e7f383f

Browse files
committedSep 28, 2022
Added maps
1 parent 5dae8c3 commit e7f383f

File tree

7 files changed

+307
-14
lines changed

7 files changed

+307
-14
lines changed
 

‎.idea/csv-plugin.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pandas as pd
88
from pnuemonia import pred_model
9+
from maps import current_location
910
from cataract import pred_model_ct
1011
from brain_tumor import pred_model_bt
1112
from flask import Flask, render_template, request
@@ -19,6 +20,8 @@
1920
parkinsons_model = pickle.load(open('models/parkinsons_model.sav', 'rb'))
2021
otherdiseases_model = pickle.load(open('models/otherdiseases.sav', 'rb'))
2122

23+
latitude, longitude = current_location()
24+
2225

2326
# reading csv and converting the data to integer
2427
def open_csv(filepath, filename):
@@ -32,6 +35,7 @@ def open_csv(filepath, filename):
3235
return data
3336

3437

38+
latitude, longitude = current_location()
3539
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
3640
ALLOWED_EXT = {'jpg', 'jpeg', 'png', 'csv'}
3741

@@ -92,7 +96,7 @@ def db_form():
9296
predictions = 'The Patient has Diabetes' + f' {(round(acc, 3) * 100)}%'
9397

9498
if (len(error) == 0):
95-
return render_template('results.html', type="csv", disease="db",
99+
return render_template('results.html', lat=latitude, lng=longitude, type="csv", disease="db",
96100
predictions=predictions,
97101
data=data_csv.to_html(classes='mystyle', index=False))
98102
else:
@@ -164,7 +168,7 @@ def hd_form():
164168
predictions = 'The Patient has Heart Disease' + f' {(round(acc, 3) * 100)}%'
165169

166170
if (len(error) == 0):
167-
return render_template('results.html', type="csv", disease="hd",
171+
return render_template('results.html', lat=latitude, lng=longitude, type="csv", disease="hd",
168172
predictions=predictions,
169173
data=data_csv.to_html(classes='mystyle', index=False))
170174
else:
@@ -256,7 +260,7 @@ def pk_form():
256260
predictions = 'The Patient has Parkinsons' + f' {(round(acc, 3) * 100)}%'
257261

258262
if (len(error) == 0):
259-
return render_template('results.html', type="csv", disease="pk",
263+
return render_template('results.html', lat=latitude, lng=longitude, type="csv", disease="pk",
260264
predictions=predictions,
261265
data=data_csv.to_html(classes='mystyle', index=False))
262266
else:
@@ -374,7 +378,7 @@ def od_form():
374378
predictions = f"{pred1[0]}" + f'{(round(acc, 3) * 100)}%'
375379

376380
if (len(error) == 0):
377-
return render_template('results.html', type="csv", disease="od",
381+
return render_template('results.html', lat=latitude, lng=longitude, type="csv", disease="od",
378382
predictions=predictions,
379383
data=data_csv.to_html(classes='mystyle', index=False))
380384
else:
@@ -391,10 +395,10 @@ def allowed_file(filename):
391395
# A common upload function for all pneumonia, HD, PK, DB and OD
392396
@app.route('/success', methods=['GET', 'POST'])
393397
def success():
394-
global predictions, file_name, data, data_csv, answer
398+
global predictions, file_name, data, data_csv, answer, latitude, longitude
395399
error = ''
396400
target_img = os.path.join(os.getcwd(), 'static/images/')
397-
401+
latitude, longitude = current_location()
398402
if request.method == 'POST':
399403

400404
if request.files:
@@ -438,7 +442,8 @@ def success():
438442
predictions = 'The Patient has diabetes' + f' {(round(acc, 3) * 100)}%'
439443

440444
if (len(error) == 0):
441-
return render_template('results.html', type="csv", disease="db",
445+
return render_template('results.html', lat=latitude, lng=longitude, type="csv",
446+
disease="db",
442447
predictions=predictions,
443448
data=data_csv.to_html(classes='mystyle', index=False))
444449
else:
@@ -462,7 +467,8 @@ def success():
462467
predictions = 'The Patient has Heart Disease' + f' {(round(acc, 3) * 100)}%'
463468

464469
if len(error) == 0:
465-
return render_template('results.html', type="csv", disease="hd",
470+
return render_template('results.html', lat=latitude, lng=longitude, type="csv",
471+
disease="hd",
466472
predictions=predictions,
467473
data=data_csv.to_html(classes='mystyle', index=False))
468474
else:
@@ -485,7 +491,8 @@ def success():
485491
predictions = 'The Patient has Parkinsons' + f' {(round(acc, 3) * 100)}%'
486492

487493
if len(error) == 0:
488-
return render_template('results.html', type="csv", disease="pk",
494+
return render_template('results.html', lat=latitude, lng=longitude, type="csv",
495+
disease="pk",
489496
predictions=predictions,
490497
data=data_csv.to_html(classes='mystyle', index=False))
491498
else:
@@ -508,7 +515,8 @@ def success():
508515

509516
if len(error) == 0:
510517

511-
return render_template('results.html', type="csv", disease="od",
518+
return render_template('results.html', lat=latitude, lng=longitude, type="csv",
519+
disease="od",
512520
predictions=predictions,
513521
data=data_csv.to_html(classes='mystyle', index=False))
514522

@@ -526,10 +534,12 @@ def success():
526534

527535
if len(error) == 0:
528536
if ".csv" in file_name:
529-
return render_template('results.html', type="csv", predictions=predictions,
537+
return render_template('results.html', lat=latitude, lng=longitude, type="csv",
538+
predictions=predictions,
530539
data=data_csv.to_html(classes='mystyle', header=False, index=False))
531540
else:
532-
return render_template('results.html', img=file_name, answer=answer, type="img", model="pneumonia",
541+
return render_template('results.html', lat=latitude, lng=longitude, img=file_name, answer=answer,
542+
type="img", model="pneumonia",
533543
predictions=predictions)
534544
else:
535545
return render_template('index.html', error=error)
@@ -563,7 +573,8 @@ def success_bt():
563573
error = "Please upload images of jpg , jpeg and png extension only"
564574

565575
if len(error) == 0:
566-
return render_template('results.html', img=file_name, answer=answer, type="img",
576+
return render_template('results.html', lat=latitude, lng=longitude, img=file_name, answer=answer,
577+
type="img",
567578
model="bt",
568579
predictions=predictions)
569580
else:
@@ -596,7 +607,8 @@ def success_ct():
596607
error = "Please upload images of jpg , jpeg and png extension only"
597608

598609
if len(error) == 0:
599-
return render_template('results.html', img=file_name, answer=answer, type="img",
610+
return render_template('results.html', lat=latitude, lng=longitude, img=file_name, answer=answer,
611+
type="img",
600612
model="ct",
601613
predictions=predictions)
602614
else:

‎csv/location.csv

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Place Name,Latitute,Longitude

‎maps.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Importing required libraries
2+
from googleplaces import GooglePlaces, types, lang
3+
import requests
4+
import json
5+
import webbrowser
6+
import numpy as np
7+
import pandas as pd
8+
import requests
9+
import json
10+
from flask import Flask, render_template, request
11+
12+
API_KEY = 'AIzaSyCDjXQWn6VopL_UcO4q6n1MYEOQrY7A7K8'
13+
14+
google_places = GooglePlaces(API_KEY)
15+
16+
17+
def current_location():
18+
send_url = "http://api.ipstack.com/check?access_key=a56ad292248979d7d292dc08aeed5ff0"
19+
geo_req = requests.get(send_url)
20+
geo_json = json.loads(geo_req.text)
21+
latitude = geo_json['latitude']
22+
longitude = geo_json['longitude']
23+
city = geo_json['city']
24+
25+
return latitude, longitude
26+
27+
28+
def nearby_hospitals(latitude, longitude):
29+
print("Latitude = ", latitude, "\n")
30+
print("Longitude = ", longitude)
31+
32+
query_result = google_places.nearby_search(
33+
lat_lng={'lat': latitude, 'lng': longitude},
34+
radius=5000,
35+
types=[types.TYPE_HOSPITAL])
36+
37+
if query_result.has_attributions:
38+
print(query_result.html_attributions)
39+
40+
for place in query_result.places:
41+
print(place)
42+
# place.get_details()
43+
print(place.name)
44+
print("Latitude", place.geo_location['lat'])
45+
print("Longitude", place.geo_location['lng'])
46+
print()
47+
48+
# app = Flask(__name__)
49+
#
50+
#
51+
# @app.route('/', methods=['GET', 'POST'])
52+
# def home():
53+
# return render_template("test.html", lat=latitude, lng =longitude)
54+
#
55+
#
56+
# # HI hrushikesh
57+
# if __name__ == "__main__":
58+
# webbrowser.open_new('http://127.0.0.1:2000/')
59+
# app.run(debug=True, port=2000)
60+
61+
62+
# df = pd.DataFrame(columns = ['Place Name', 'Latitude', 'Longitude'])
63+
# # Iterate over the search results
64+
# for place in query_result.places:
65+
# print(place)
66+
# # place.get_details()
67+
# print(place.name)
68+
# print("Latitude", place.geo_location['lat'])
69+
# print("Longitude", place.geo_location['lng'])
70+
# print()
71+
# df['Place Name'].append(place.name)
72+
# df['Latitude'].append(place.geo_location['lat'])
73+
# df['Longitude'].append(place.geo_location['lng'])
74+
#
75+
#
76+
# print(df)

‎static/images/cataract_033.png

2.85 MB
Loading

‎templates/results.html

+90
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,97 @@ <h2>The patient is {{predictions[0].split("_")[0]}}</h2>
166166
{% else %}
167167
Don't understand!
168168
{% endif %}
169+
<section id="services" class="features">
170+
<div class="container">
171+
172+
<div class="section-title" data-aos="fade-up">
173+
<h2>Recommended Hospitals</h2>
174+
<p>Hospitals and Medicals Nearby</p>
175+
</div>
169176

177+
<div id="map"></div>
178+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCDjXQWn6VopL_UcO4q6n1MYEOQrY7A7K8&libraries=places&callback=initMap" async defer></script>
179+
180+
<style>
181+
html,
182+
body {
183+
margin: 0;
184+
padding: 0;
185+
}
186+
187+
#map {
188+
height: 500px;
189+
margin: 10px auto;
190+
width: 800px;
191+
}
192+
</style>
193+
<script>
194+
var map;
195+
196+
function initMap() {
197+
// Create the map.
198+
var pyrmont = {
199+
lat: {{lat}} ,
200+
lng: {{lng}}
201+
};
202+
if (navigator.geolocation) {
203+
try {
204+
navigator.geolocation.getCurrentPosition(function(position) {
205+
var pyrmont = {
206+
lat: position.coords.latitude,
207+
lng: position.coords.longitude
208+
};
209+
});
210+
} catch (err) {
211+
212+
}
213+
}
214+
map = new google.maps.Map(document.getElementById('map'), {
215+
center: pyrmont,
216+
zoom: 17
217+
});
218+
219+
// Create the places service.
220+
var service = new google.maps.places.PlacesService(map);
221+
222+
// Perform a nearby search.
223+
service.nearbySearch({
224+
location: pyrmont,
225+
radius: 4000,
226+
type: ['hospital']
227+
},
228+
function(results, status, pagination) {
229+
if (status !== 'OK') return;
230+
231+
createMarkers(results);
232+
getNextPage = pagination.hasNextPage && function() {
233+
pagination.nextPage();
234+
};
235+
});
236+
}
237+
238+
function createMarkers(places) {
239+
var bounds = new google.maps.LatLngBounds();
240+
for (var i = 0, place; place = places[i]; i++) {
241+
var image = {
242+
url: place.icon,
243+
size: new google.maps.Size(71, 71),
244+
origin: new google.maps.Point(0, 0),
245+
anchor: new google.maps.Point(17, 34),
246+
scaledSize: new google.maps.Size(25, 25)
247+
};
248+
249+
var marker = new google.maps.Marker({
250+
map: map,
251+
icon: image,
252+
title: place.name,
253+
position: place.geometry.location
254+
});
255+
bounds.extend(place.geometry.location);
256+
}
257+
map.fitBounds(bounds);
258+
}
259+
</script>
170260

171261
</div>
172262
</section>

0 commit comments

Comments
 (0)