Clément Simon commited on
Commit
135bbd4
1 Parent(s): 4a533cc

feat: collapsible menu + map

Browse files

fix: hugging face missing api secrets

Files changed (5) hide show
  1. .gitignore +1 -1
  2. app.py +19 -0
  3. static/layout.html +55 -26
  4. static/script.js +6 -8
  5. static/style.css +164 -9
.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- .env
2
  .venv
3
  __pycache__
4
  static/map.html
 
1
+ *.env
2
  .venv
3
  __pycache__
4
  static/map.html
app.py CHANGED
@@ -20,6 +20,25 @@ today = date.today()
20
  today = today.strftime("%Y-%m-%d")
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # Load environment variables
24
  load_dotenv()
25
  api_key = os.getenv('API_KEY')
 
20
  today = today.strftime("%Y-%m-%d")
21
 
22
 
23
+ # Hugging face space secret retrieval:
24
+ def create_env_file():
25
+ import os
26
+
27
+ secrets = ['API_KEY', 'AGRO_API_KEY', 'OPENCAGE_API_KEY']
28
+ for secret in secrets:
29
+ secret_value = os.environ[secret]
30
+ if secret_value is None:
31
+ print(f"Please set the environment variable {secret}")
32
+ else:
33
+ with open('.env', 'a') as f:
34
+ f.write(f"{secret}={secret_value}\n")
35
+
36
+ # Hugging face space secret retrieval:
37
+ production = True
38
+ if production:
39
+ create_env_file()
40
+
41
+
42
  # Load environment variables
43
  load_dotenv()
44
  api_key = os.getenv('API_KEY')
static/layout.html CHANGED
@@ -1,34 +1,63 @@
1
  <!DOCTYPE html>
2
  <html>
3
- <head>
4
- <title>FastAPI Home</title>
5
- <link rel="stylesheet" href="/static/style.css" />
6
- </head>
7
- <body>
8
- <h1>FastAPI Home</h1>
9
- <div id="leftMenu" class="side-menu">
10
- <ul id="Profile">
11
- <li>Name: {{ user_profile.name }}</li>
12
- <li>Age: {{ user_profile.age }}</li>
13
- <li>Location: {{ user_profile.location }}</li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  </ul>
15
- <button id="toggleMenu">Toggle Menu</button>
16
  </div>
17
-
 
 
18
  <div id="mainContent">
19
  <div id="map" class="map">{{ map_html | safe }}</div>
20
  </div>
21
-
22
- <div id="rightProfile" class="side-menu">
23
- <button id="toggleProfile">Toggle Profile</button>
24
-
25
- <div id="chat">
26
- <input type="text" id="user_input" placeholder="Enter your message" />
27
- <button onclick="sendChat()">Send</button>
28
- <ul id="chat_messages"></ul>
29
- </div>
30
- </div>
31
-
32
- <script src="/static/script.js"></script>
33
- </body>
34
  </html>
 
1
  <!DOCTYPE html>
2
  <html>
3
+ <link rel="stylesheet" href="/static/style.css" />
4
+ <header>
5
+ <nav>
6
+ <ul class="menus">
7
+ <li class="main">
8
+ <a href="#">
9
+ <i class="fas fa-bars"></i>
10
+ </a>
11
+ </li>
12
+ <li class="menu">
13
+ <a href="#">
14
+ <i class="fas fa-home"></i>
15
+ </a>
16
+ </li>
17
+ <li class="menu">
18
+ <a href="#">
19
+ <i class="fas fa-sliders-h"></i>
20
+ </a>
21
+ </li>
22
+ <li class="menu">
23
+ <a href="#">
24
+ <i class="fas fa-cog"></i>
25
+ </a>
26
+ </li>
27
+ </ul>
28
+ </nav>
29
+ </header>
30
+ <div class="app flexed">
31
+ <div class="spacer">
32
+ <ul class="submenus">
33
+ <li class="main"><span>Menus</span></li>
34
+ <li class="submenu">
35
+ <a href="#">Chat</a>
36
+ <div id="chat">
37
+ <input
38
+ type="text"
39
+ id="user_input"
40
+ placeholder="Enter your message"
41
+ />
42
+ <button onclick="sendChat()">Send</button>
43
+ <ul id="chat_messages"></ul>
44
+ </div>
45
+ </li>
46
+ <li class="submenu">
47
+ <a href="#">Profile</a>
48
+ <ul id="Profile">
49
+ <li>Name: {{ user_profile.name }}</li>
50
+ <li>Age: {{ user_profile.age }}</li>
51
+ <li>Location: {{ user_profile.location }}</li>
52
+ </ul>
53
+ </li>
54
  </ul>
 
55
  </div>
56
+ </div>
57
+ <body>
58
+ <h1>FastAPI Home</h1>
59
  <div id="mainContent">
60
  <div id="map" class="map">{{ map_html | safe }}</div>
61
  </div>
62
+ <script src="/static/script.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
63
  </html>
static/script.js CHANGED
@@ -1,12 +1,10 @@
1
- document.getElementById('toggleMenu').addEventListener('click', function () {
2
- var menu = document.getElementById('leftMenu');
3
- menu.classList.toggle('hidden');
4
- });
 
 
5
 
6
- document.getElementById('toggleProfile').addEventListener('click', function () {
7
- var profile = document.getElementById('rightProfile');
8
- profile.classList.toggle('hidden');
9
- });
10
 
11
  function sendChat() {
12
  var user_input = document.getElementById("user_input").value;
 
1
+ if (document.querySelector(".main")) {
2
+ document.querySelector(".main").onclick = function (){
3
+ var submenu = document.querySelector(".spacer");
4
+ submenu.classList.toggle("show");
5
+ }
6
+ }
7
 
 
 
 
 
8
 
9
  function sendChat() {
10
  var user_input = document.getElementById("user_input").value;
static/style.css CHANGED
@@ -1,24 +1,179 @@
1
- .side-menu {
2
- width: 200px;
3
- /* Fixed width */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  position: fixed;
5
  top: 0;
6
- overflow: auto;
 
 
7
  height: 100%;
 
 
 
 
 
 
 
8
  }
9
 
10
- #leftMenu {
11
- left: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  }
13
 
14
- #rightProfile {
15
- right: 0;
 
16
  }
17
 
18
- .hidden {
19
  display: none;
20
  }
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  .map {
23
  /* show full screen the iframe */
24
  position: fixed;
 
1
+ html {
2
+ font-family: sans-serif;
3
+ -webkit-text-size-adjust: 100%;
4
+ -ms-text-size-adjust: 100%;
5
+ }
6
+
7
+ body {
8
+ margin: 0;
9
+ }
10
+
11
+ header,
12
+ nav {
13
+ display: block;
14
+ }
15
+
16
+ a {
17
+ background-color: transparent;
18
+ color: inherit;
19
+ text-decoration: none;
20
+ }
21
+
22
+ a:active,
23
+ a:hover {
24
+ outline: 0;
25
+ }
26
+
27
+ img {
28
+ border: 0;
29
+ }
30
+
31
+ ul {
32
+ list-style: none;
33
+ margin: 0;
34
+ -webkit-margin-before: 0;
35
+ -webkit-margin-after: 0;
36
+ -webkit-margin-start: 0;
37
+ -webkit-margin-end: 0;
38
+ -webkit-padding-start: 0px;
39
+ }
40
+
41
+ header {
42
  position: fixed;
43
  top: 0;
44
+ left: 0;
45
+ bottom: 0;
46
+ width: 100px;
47
  height: 100%;
48
+ min-height: 0;
49
+ min-width: 100px;
50
+ overflow-y: auto;
51
+ transition: 500ms;
52
+ background-color: rgb(56, 82, 102);
53
+ border-right: 1px solid #ffffff80;
54
+ z-index: 10;
55
  }
56
 
57
+ .flexed {
58
+ display: flex;
59
+ }
60
+
61
+ .spacer {
62
+ display: inline-block;
63
+ position: relative;
64
+ height: 100%;
65
+ width: 10vw;
66
+ min-width: 110px;
67
+ }
68
+
69
+ .menus {
70
+ display: flex;
71
+ flex-direction: column;
72
+ justify-content: flex-start;
73
+ align-items: center;
74
+ width: 100%;
75
+ min-height: 400px;
76
+ text-align: center;
77
+ }
78
+
79
+ .main {
80
+ padding: 1em 1em 0.8em;
81
+ border-bottom: 1px solid #FFF;
82
+ color: #f1f1f1;
83
+ }
84
+
85
+ .menu {
86
+ margin: 0.5em 0 0;
87
+ color: #f1f1f1;
88
+ transition: 0.5s;
89
+ font-size: 1.5rem;
90
+ padding: 0.5em 0;
91
+ border-bottom: 1px solid #ececec;
92
+ width: 33.333%;
93
+ }
94
+
95
+ .menu:hover {
96
+ color: #ececec;
97
+ background-color: rgba(11, 123, 132, 1);
98
+ border: 1px solid #FFF;
99
+ border-radius: 50%;
100
+ padding: 0.3em;
101
+ box-shadow: 0 0 5px 0 #000;
102
+ }
103
+
104
+ .spacer {
105
+ transition: 300ms;
106
  }
107
 
108
+ .spacer.show {
109
+ width: auto;
110
+ margin-right: 1em;
111
  }
112
 
113
+ .spacer .submenus {
114
  display: none;
115
  }
116
 
117
+ .spacer.show .submenus {
118
+ display: flex;
119
+ flex-direction: column;
120
+ justify-content: flex-start;
121
+ width: 300px;
122
+ height: 100vh;
123
+ min-height: 100px;
124
+ margin-left: 100px;
125
+ padding-left: 1em;
126
+ text-align: left;
127
+ background-color: rgb(56, 82, 102);
128
+ animation: sulod 300ms linear;
129
+ -webkit-animation: sulod 300ms linear;
130
+ }
131
+
132
+ .submenu {
133
+ margin: 0.5em 0 0;
134
+ color: #FFF;
135
+ transition: 0.5s;
136
+ font-size: 90%;
137
+ line-height: 2.2rem;
138
+ padding: 0.5em 0;
139
+ }
140
+
141
+ .spacer .main {
142
+ border: none;
143
+ color: transparent;
144
+ }
145
+
146
+ @keyframes sulod {
147
+ 0% {
148
+ transform: translateX(-100%);
149
+ }
150
+
151
+ 100% {
152
+ transform: translateX(0%);
153
+ }
154
+ }
155
+
156
+ @-moz-keyframes sulod {
157
+ 0% {
158
+ transform: translateX(-100%);
159
+ }
160
+
161
+ 100% {
162
+ transform: translateX(0%);
163
+ }
164
+ }
165
+
166
+ @-webkit-keyframes sulod {
167
+ 0% {
168
+ transform: translateX(-100%);
169
+ }
170
+
171
+ 100% {
172
+ transform: translateX(0%);
173
+ }
174
+ }
175
+
176
+
177
  .map {
178
  /* show full screen the iframe */
179
  position: fixed;