Iisakki Rotko commited on
Commit
2fb381b
1 Parent(s): 1ec2294

fix: It's pretty now

Browse files
Files changed (1) hide show
  1. wanderlust.py +62 -24
wanderlust.py CHANGED
@@ -6,7 +6,7 @@ import openai
6
 
7
  import solara
8
 
9
- center_default = (53.2305799, 6.5323552)
10
  zoom_default = 2
11
 
12
  messages_default = []
@@ -30,7 +30,10 @@ function_descriptions = [
30
  "parameters": {
31
  "type": "object",
32
  "properties": {
33
- "longitude": {"type": "number", "description": "Longitude of the location to center the map on"},
 
 
 
34
  "latitude": {
35
  "type": "number",
36
  "description": "Latitude of the location to center the map on",
@@ -52,7 +55,10 @@ function_descriptions = [
52
  "parameters": {
53
  "type": "object",
54
  "properties": {
55
- "longitude": {"type": "number", "description": "Longitude of the location to the marker"},
 
 
 
56
  "latitude": {
57
  "type": "number",
58
  "description": "Latitude of the location to the marker",
@@ -112,7 +118,10 @@ def Map():
112
  scroll_wheel_zoom=True,
113
  layers=[
114
  ipyleaflet.TileLayer.element(url=url),
115
- *[ipyleaflet.Marker.element(location=k["location"], draggable=False) for k in markers.value],
 
 
 
116
  ],
117
  )
118
 
@@ -165,26 +174,41 @@ def ChatInterface():
165
 
166
  solara.use_effect(handle_initial, [])
167
  result = solara.use_thread(ask, dependencies=[messages.value])
168
- with solara.Column(style={"height": "100%"}):
169
- with solara.Column(style={"height": "100%", "overflow-y": "auto"}, classes=["chat-interface"]):
170
- for message in messages.value:
171
- if message["role"] == "user":
172
- solara.Text(message["content"], classes=["chat-message", "user-message"])
173
- elif message["role"] == "assistant":
174
- if message["content"]:
175
- solara.Markdown(message["content"])
176
- elif message["tool_calls"]:
177
- solara.Markdown("*Calling map functions*")
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  else:
179
- solara.Preformatted(repr(message), classes=["chat-message", "assistant-message"])
180
- elif message["role"] == "tool":
181
- pass # no need to display
182
- else:
183
- solara.Preformatted(repr(message), classes=["chat-message", "assistant-message"])
184
- # solara.Text(message, classes=["chat-message"])
185
  with solara.Column():
186
  solara.InputText(
187
- label="Ask your ", value=prompt, style={"flex-grow": "1"}, on_value=add_message, disabled=result.state == solara.ResultState.RUNNING
 
 
 
 
188
  )
189
  solara.ProgressLinear(result.state == solara.ResultState.RUNNING)
190
  if result.state == solara.ResultState.ERROR:
@@ -210,14 +234,28 @@ def Page():
210
  messages.set(json.load(f))
211
  reset_ui()
212
 
213
- with solara.Column(style={"height": "100%"}):
214
  with solara.AppBar():
215
  solara.Button("Save", on_click=save)
216
  solara.Button("Load", on_click=load)
217
  solara.Button("Soft reset", on_click=reset_ui)
218
- with solara.Columns(style={"height": "100%"}):
219
  ChatInterface().key(f"chat-{reset_counter}")
220
- Map() # .key(f"map-{reset_counter}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
 
223
  # TODO: custom layout
 
6
 
7
  import solara
8
 
9
+ center_default = (0, 0)
10
  zoom_default = 2
11
 
12
  messages_default = []
 
30
  "parameters": {
31
  "type": "object",
32
  "properties": {
33
+ "longitude": {
34
+ "type": "number",
35
+ "description": "Longitude of the location to center the map on",
36
+ },
37
  "latitude": {
38
  "type": "number",
39
  "description": "Latitude of the location to center the map on",
 
55
  "parameters": {
56
  "type": "object",
57
  "properties": {
58
+ "longitude": {
59
+ "type": "number",
60
+ "description": "Longitude of the location to the marker",
61
+ },
62
  "latitude": {
63
  "type": "number",
64
  "description": "Latitude of the location to the marker",
 
118
  scroll_wheel_zoom=True,
119
  layers=[
120
  ipyleaflet.TileLayer.element(url=url),
121
+ *[
122
+ ipyleaflet.Marker.element(location=k["location"], draggable=False)
123
+ for k in markers.value
124
+ ],
125
  ],
126
  )
127
 
 
174
 
175
  solara.use_effect(handle_initial, [])
176
  result = solara.use_thread(ask, dependencies=[messages.value])
177
+ with solara.Column(
178
+ style={"height": "100%", "width": "38vw", "justify-content": "center"},
179
+ classes=["chat-interface"],
180
+ ):
181
+ if len(messages.value) > 0:
182
+ with solara.Column(style={"flex-grow": "1", "overflow-y": "auto"}):
183
+ for message in messages.value:
184
+ if message["role"] == "user":
185
+ solara.Text(
186
+ message["content"], classes=["chat-message", "user-message"]
187
+ )
188
+ elif message["role"] == "assistant":
189
+ if message["content"]:
190
+ solara.Markdown(message["content"])
191
+ elif message["tool_calls"]:
192
+ solara.Markdown("*Calling map functions*")
193
+ else:
194
+ solara.Preformatted(
195
+ repr(message),
196
+ classes=["chat-message", "assistant-message"],
197
+ )
198
+ elif message["role"] == "tool":
199
+ pass # no need to display
200
  else:
201
+ solara.Preformatted(
202
+ repr(message), classes=["chat-message", "assistant-message"]
203
+ )
204
+ # solara.Text(message, classes=["chat-message"])
 
 
205
  with solara.Column():
206
  solara.InputText(
207
+ label="Ask your ",
208
+ value=prompt,
209
+ style={"flex-grow": "1"},
210
+ on_value=add_message,
211
+ disabled=result.state == solara.ResultState.RUNNING,
212
  )
213
  solara.ProgressLinear(result.state == solara.ResultState.RUNNING)
214
  if result.state == solara.ResultState.ERROR:
 
234
  messages.set(json.load(f))
235
  reset_ui()
236
 
237
+ with solara.Column(style={"flex-grow": "1"}, gap=0):
238
  with solara.AppBar():
239
  solara.Button("Save", on_click=save)
240
  solara.Button("Load", on_click=load)
241
  solara.Button("Soft reset", on_click=reset_ui)
242
+ with solara.Row(style={"height": "100%"}, justify="space-between"):
243
  ChatInterface().key(f"chat-{reset_counter}")
244
+ with solara.Column(style={"width": "58vw", "justify-content": "center"}):
245
+ Map() # .key(f"map-{reset_counter}")
246
+
247
+ solara.Style(
248
+ """
249
+ .jupyter-widgets.leaflet-widgets{
250
+ height: 100%;
251
+ }
252
+ .solara-autorouter-content{
253
+ display: flex;
254
+ flex-direction: column;
255
+ justify-content: stretch;
256
+ }
257
+ """
258
+ )
259
 
260
 
261
  # TODO: custom layout