molokhovdmitry
commited on
Commit
·
01142fd
1
Parent(s):
0ad49be
Map update
Browse filesFormer-commit-id: 2e9ad04139c6f154fb12ee54a66a703a3bb43e13
Former-commit-id: e63c943e2fa038179e19e9f6d2ad8a0c029aa193
- main.py +10 -7
- map.py +0 -52
- mapbox_map.py +59 -0
- wikipedia_api.py +8 -4
main.py
CHANGED
@@ -7,6 +7,7 @@ import io
|
|
7 |
from model_execute import preprocess_images, output_to_names
|
8 |
from summarization import init_model_and_tokenizer, summarize
|
9 |
from wikipedia_api import getWikipedia
|
|
|
10 |
|
11 |
@st.cache_resource
|
12 |
def load_recognition_model():
|
@@ -70,22 +71,24 @@ st.title("Распознавание достопримечательносте
|
|
70 |
# Images input.
|
71 |
images = load_images()
|
72 |
|
|
|
73 |
result = st.button('Распознать')
|
74 |
|
75 |
-
if result:
|
76 |
# Get predictions
|
77 |
names = predict_images(images, landmark_model)
|
78 |
st.write(names)
|
79 |
|
80 |
# Request descriptions and coordinates from Wikipedia.
|
81 |
wiki_data = getWikipedia(names)
|
82 |
-
|
83 |
# Summarize descriptions for each landmark.
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
st.write(wiki_data)
|
90 |
|
91 |
# Draw a map.
|
|
|
|
7 |
from model_execute import preprocess_images, output_to_names
|
8 |
from summarization import init_model_and_tokenizer, summarize
|
9 |
from wikipedia_api import getWikipedia
|
10 |
+
from mapbox_map import plot_map
|
11 |
|
12 |
@st.cache_resource
|
13 |
def load_recognition_model():
|
|
|
71 |
# Images input.
|
72 |
images = load_images()
|
73 |
|
74 |
+
summarize_checkbox = st.checkbox("Короткое описание")
|
75 |
result = st.button('Распознать')
|
76 |
|
77 |
+
if images and result:
|
78 |
# Get predictions
|
79 |
names = predict_images(images, landmark_model)
|
80 |
st.write(names)
|
81 |
|
82 |
# Request descriptions and coordinates from Wikipedia.
|
83 |
wiki_data = getWikipedia(names)
|
84 |
+
st.write("Загружены данные с википедии.")
|
85 |
# Summarize descriptions for each landmark.
|
86 |
+
if summarize_checkbox:
|
87 |
+
for landmark in wiki_data:
|
88 |
+
description = landmark['summary']
|
89 |
+
summarized = summarize(description, summarizer, tokenizer)
|
90 |
+
landmark['summarized'] = summarized
|
91 |
st.write(wiki_data)
|
92 |
|
93 |
# Draw a map.
|
94 |
+
plot_map(wiki_data)
|
map.py
DELETED
@@ -1,52 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import plotly.graph_objects as go
|
4 |
-
|
5 |
-
# Загрузка данных
|
6 |
-
data = pd.DataFrame({
|
7 |
-
'latitude': [37.7749, 34.0522], # Пример координат для точек
|
8 |
-
'longitude': [-122.4194, -118.2437],
|
9 |
-
'name': ['San Francisco', 'Los Angeles']
|
10 |
-
})
|
11 |
-
|
12 |
-
# Заголовок приложения
|
13 |
-
st.title('Приложение с картой MapBox')
|
14 |
-
|
15 |
-
# Создание маркеров
|
16 |
-
marker_size = 12 # Размер маркера
|
17 |
-
|
18 |
-
fig = go.Figure()
|
19 |
-
|
20 |
-
for i, row in data.iterrows():
|
21 |
-
fig.add_trace(go.Scattermapbox(
|
22 |
-
lat=[row['latitude']],
|
23 |
-
lon=[row['longitude']],
|
24 |
-
mode='markers',
|
25 |
-
marker=dict(
|
26 |
-
size=marker_size,
|
27 |
-
color='red',
|
28 |
-
sizemode='diameter', # Размер маркера в диаметрах
|
29 |
-
),
|
30 |
-
text=row['name']
|
31 |
-
))
|
32 |
-
|
33 |
-
# Вычисление границы области, содержащей все маркеры
|
34 |
-
min_lat, max_lat = data['latitude'].min(), data['latitude'].max()
|
35 |
-
min_lon, max_lon = data['longitude'].min(), data['longitude'].max()
|
36 |
-
|
37 |
-
# Рассчитываем центр и масштаб для отображения всех маркеров
|
38 |
-
center_lat = (min_lat + max_lat) / 2
|
39 |
-
center_lon = (min_lon + max_lon) / 2
|
40 |
-
zoom_level = 1 # Масштаб (может потребоваться настройка)
|
41 |
-
|
42 |
-
# Настройка карты
|
43 |
-
fig.update_layout(
|
44 |
-
mapbox_style="open-street-map",
|
45 |
-
mapbox=dict(
|
46 |
-
center=dict(lat=center_lat, lon=center_lon),
|
47 |
-
zoom=zoom_level,
|
48 |
-
),
|
49 |
-
)
|
50 |
-
|
51 |
-
# Отображение карты в Streamlit
|
52 |
-
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapbox_map.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
|
5 |
+
def preprocess_df(df):
|
6 |
+
"""
|
7 |
+
Убрать строки без координат, преобразовать координаты в float.
|
8 |
+
"""
|
9 |
+
no_coords = df['latitude'] == ''
|
10 |
+
df = df.drop(df[no_coords].index)
|
11 |
+
df['latitude'] = df['latitude'].astype('float')
|
12 |
+
df['longitude'] = df['longitude'].astype('float')
|
13 |
+
return df
|
14 |
+
|
15 |
+
def plot_map(landmarks):
|
16 |
+
# Загрузка данных
|
17 |
+
data = pd.DataFrame(landmarks)
|
18 |
+
data = preprocess_df(data)
|
19 |
+
st.write(data)
|
20 |
+
# Создание маркеров
|
21 |
+
marker_size = 12 # Размер маркера
|
22 |
+
|
23 |
+
fig = go.Figure()
|
24 |
+
|
25 |
+
for i, row in data.iterrows():
|
26 |
+
if type(row['latitude']) is not float:
|
27 |
+
continue
|
28 |
+
fig.add_trace(go.Scattermapbox(
|
29 |
+
lat=[row['latitude']],
|
30 |
+
lon=[row['longitude']],
|
31 |
+
mode='markers',
|
32 |
+
marker=dict(
|
33 |
+
size=marker_size,
|
34 |
+
color='red',
|
35 |
+
sizemode='diameter', # Размер маркера в диаметрах
|
36 |
+
),
|
37 |
+
text=row['find']
|
38 |
+
))
|
39 |
+
|
40 |
+
# Вычисление границы области, содержащей все маркеры
|
41 |
+
min_lat, max_lat = data['latitude'].min(), data['latitude'].max()
|
42 |
+
min_lon, max_lon = data['longitude'].min(), data['longitude'].max()
|
43 |
+
|
44 |
+
# Рассчитываем центр и масштаб для отображения всех маркеров
|
45 |
+
center_lat = (min_lat + max_lat) / 2
|
46 |
+
center_lon = (min_lon + max_lon) / 2
|
47 |
+
zoom_level = 12 # Масштаб (может потребоваться настройка)
|
48 |
+
|
49 |
+
# Настройка карты
|
50 |
+
fig.update_layout(
|
51 |
+
mapbox_style="open-street-map",
|
52 |
+
mapbox=dict(
|
53 |
+
center=dict(lat=center_lat, lon=center_lon),
|
54 |
+
zoom=zoom_level,
|
55 |
+
),
|
56 |
+
)
|
57 |
+
|
58 |
+
# Отображение карты в Streamlit
|
59 |
+
st.plotly_chart(fig)
|
wikipedia_api.py
CHANGED
@@ -26,12 +26,16 @@ def getWikipedia(pList):
|
|
26 |
longitude = find['data-lon']
|
27 |
else:
|
28 |
summary = 'Ничего не найдено'
|
29 |
-
|
30 |
res = {'find':i,
|
31 |
-
'summary':summary,
|
32 |
-
'latitude':latitude,
|
33 |
-
'longitude':longitude,
|
34 |
}
|
35 |
result.append(res)
|
36 |
|
37 |
return result
|
|
|
|
|
|
|
|
|
|
26 |
longitude = find['data-lon']
|
27 |
else:
|
28 |
summary = 'Ничего не найдено'
|
29 |
+
|
30 |
res = {'find':i,
|
31 |
+
'summary': summary,
|
32 |
+
'latitude': latitude,
|
33 |
+
'longitude': longitude,
|
34 |
}
|
35 |
result.append(res)
|
36 |
|
37 |
return result
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
|
41 |
+
print(getWikipedia(["Новый Арбат"]))
|