methestrikerx100 commited on
Commit
87836ca
·
verified ·
1 Parent(s): eeaef06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -0
app.py CHANGED
@@ -5,6 +5,120 @@ import cv2
5
  import gradio as gr
6
  from tensorflow import keras
7
  from keras.models import load_model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Load the CNN feature extractor model
10
  from tensorflow.keras.models import load_model
 
5
  import gradio as gr
6
  from tensorflow import keras
7
  from keras.models import load_model
8
+ import folium
9
+
10
+
11
+
12
+
13
+ # CODE FOR MAPS
14
+ def convert_coordinates(coord_str):
15
+ # Regular expression pattern to match the coordinate format
16
+ pattern = r"(\d+)°(\d+)'(\d+(?:\.\d+)?)\"([NS])\s+(\d+)°(\d+)'(\d+(?:\.\d+)?)\"([EW])"
17
+
18
+ match = re.match(pattern, coord_str)
19
+
20
+ if match:
21
+ lat_deg = int(match.group(1))
22
+ lat_min = int(match.group(2))
23
+ lat_sec = float(match.group(3))
24
+ lat_dir = match.group(4)
25
+
26
+ lon_deg = int(match.group(5))
27
+ lon_min = int(match.group(6))
28
+ lon_sec = float(match.group(7))
29
+ lon_dir = match.group(8)
30
+
31
+ # Convert coordinates to decimal format
32
+ lat_decimal = lat_deg + (lat_min / 60) + (lat_sec / 3600)
33
+ lon_decimal = lon_deg + (lon_min / 60) + (lon_sec / 3600)
34
+
35
+ # Apply sign based on direction
36
+ if lat_dir == 'S':
37
+ lat_decimal *= -1
38
+ if lon_dir == 'W':
39
+ lon_decimal *= -1
40
+
41
+ return (lat_decimal, lon_decimal)
42
+ else:
43
+ return None
44
+
45
+ # Example usage
46
+ coordinates = "30°01'48.7\"N 30°58'35.1\"E"
47
+ latitude, longitude = convert_coordinates(coordinates)
48
+ print(f"Latitude: {latitude}, Longitude: {longitude}")
49
+
50
+
51
+ mineral_locations = {
52
+ 'biotite': [
53
+ convert_coordinates("45°26'54.0\"N 75°41'24.0\"W"),
54
+ convert_coordinates("51°03'07.2\"N 114°04'28.8\"W"),
55
+ convert_coordinates("37°47'24.0\"N 122°28'12.0\"W")
56
+ ],
57
+ 'granite': [
58
+ convert_coordinates("40°44'54.0\"N 73°59'08.0\"W"),
59
+ convert_coordinates("34°03'08.0\"S 151°06'24.0\"E"),
60
+ convert_coordinates("55°45'00.0\"N 37°37'00.0\"E")
61
+ ],
62
+ 'olivine': [
63
+ convert_coordinates("19°28'48.0\"N 155°36'00.0\"W"),
64
+ convert_coordinates("38°41'24.0\"N 9°08'24.0\"W"),
65
+ convert_coordinates("46°28'12.0\"N 7°57'36.0\"E")
66
+ ],
67
+ 'plagioclase': [
68
+ convert_coordinates("48°51'24.0\"N 2°21'05.0\"E"),
69
+ convert_coordinates("35°40'48.0\"N 139°41'24.0\"E"),
70
+ convert_coordinates("41°53'24.0\"N 12°29'24.0\"E")
71
+ ],
72
+ 'staurolite': [
73
+ convert_coordinates("43°04'12.0\"N 89°22'48.0\"W"),
74
+ convert_coordinates("47°36'00.0\"N 7°36'00.0\"E"),
75
+ convert_coordinates("51°30'00.0\"N 0°07'48.0\"W")
76
+ ]
77
+ }
78
+
79
+
80
+
81
+ import folium
82
+
83
+ def plot_mineral_locations(mineral_locations):
84
+ map = folium.Map(location=[0, 0], zoom_start=2)
85
+
86
+ for mineral, locations in mineral_locations.items():
87
+ for location in locations:
88
+ lat, lon = location
89
+ folium.Marker(
90
+ location=[lat, lon],
91
+ popup=mineral,
92
+ icon=folium.Icon(color='green')
93
+ ).add_to(map)
94
+
95
+ return map
96
+
97
+
98
+ def generate_mineral_map(mineral_name):
99
+ # Create a map object
100
+ mineral_map = folium.Map(location=[0, 0], zoom_start=2)
101
+
102
+ # Get the locations for the specified mineral
103
+ locations = mineral_locations.get(mineral_name, [])
104
+
105
+ # Add markers for the mineral locations
106
+ for location in locations:
107
+ lat, lon = location
108
+ folium.Marker(
109
+ location=[lat, lon],
110
+ popup=mineral_name,
111
+ icon=folium.Icon(color='green')
112
+ ).add_to(mineral_map)
113
+
114
+ return mineral_map
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
 
123
  # Load the CNN feature extractor model
124
  from tensorflow.keras.models import load_model