-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrettyMap.py
More file actions
50 lines (48 loc) · 1.83 KB
/
PrettyMap.py
File metadata and controls
50 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
from prettymaps import plot
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
from PIL import Image
import os
st.title("Pretty Maps Application")
st.sidebar.title("Input")
form = st.sidebar.form("my_form")
place = form.text_area("Enter the place that you want to see the map")
circle = form.checkbox("Circle")
rad = form.slider("Radius", 1000, 10000, 2000, 100)
p_name = form.text_input("Title of figure:")
submit = form.form_submit_button("Submit")
if submit:
try:
with st.spinner(f'Building a map of {p_name}.. Hold On...'):
fig, ax = plt.subplots(figsize = (13, 13), constrained_layout = True)
figure = plot(
place,
circle = circle,
radius = rad,
ax=ax
)
fig.patch.set_facecolor('#F2F4CB')
ax.set_title(
p_name,
fontproperties = FontProperties(
size = 50
)
)
plt.savefig(f"{p_name}.jpeg", dpi=600)
# figure.savefig(f"{p_name}.jpg")
figure = Image.open(f"{p_name}.jpeg")
st.image(figure)
with open(f"{p_name}.jpeg", "rb") as file:
st.download_button("Download Map",
data=file,
file_name=f"{p_name}.jpeg",
mime="image/png")
files = os.listdir(os.curdir)
for item in files:
if item.endswith(".jpeg"):
os.remove(os.path.join(os.curdir, item))
except:
st.warning("The place that you typed does not exist or the format is wrong")
else:
st.info("Enter a place")