Spaces:
Running
Running
Commit
·
d7640ce
1
Parent(s):
075f67d
Completed - part 2
Browse files
main.py
CHANGED
@@ -1,5 +1,91 @@
|
|
1 |
import mesop as me
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def page():
|
5 |
-
me.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import mesop as me
|
2 |
|
3 |
+
ROOT_BOX_STYLE = me.Style(
|
4 |
+
background="#e7f2ff",
|
5 |
+
height="100%",
|
6 |
+
font_family="Inter",
|
7 |
+
display="flex",
|
8 |
+
flex_direction="column",
|
9 |
+
)
|
10 |
+
|
11 |
+
@me.page(
|
12 |
+
path="/",
|
13 |
+
stylesheets=[
|
14 |
+
"https://fonts.googleapis.com/css2?family=Inter:[email protected]&display=swap"
|
15 |
+
],
|
16 |
+
)
|
17 |
def page():
|
18 |
+
with me.box(style=ROOT_BOX_STYLE):
|
19 |
+
header()
|
20 |
+
with me.box(
|
21 |
+
style=me.Style(
|
22 |
+
width="min(680px, 100%)",
|
23 |
+
margin=me.Margin.symmetric(
|
24 |
+
horizontal="auto",
|
25 |
+
vertical=36,
|
26 |
+
),
|
27 |
+
)
|
28 |
+
):
|
29 |
+
me.text(
|
30 |
+
"Chat with multiple models at once",
|
31 |
+
style=me.Style(
|
32 |
+
font_size=20,
|
33 |
+
margin=me.Margin(bottom=24),
|
34 |
+
),
|
35 |
+
)
|
36 |
+
chat_input()
|
37 |
+
|
38 |
+
def header():
|
39 |
+
with me.box(
|
40 |
+
style=me.Style(
|
41 |
+
padding=me.Padding.all(16),
|
42 |
+
),
|
43 |
+
):
|
44 |
+
me.text(
|
45 |
+
"DuoChat",
|
46 |
+
style=me.Style(
|
47 |
+
font_weight=500,
|
48 |
+
font_size=24,
|
49 |
+
color="#3D3929",
|
50 |
+
letter_spacing="0.3px",
|
51 |
+
),
|
52 |
+
)
|
53 |
+
|
54 |
+
@me.stateclass
|
55 |
+
class State:
|
56 |
+
input: str = ""
|
57 |
+
|
58 |
+
def on_blur(e: me.InputBlurEvent):
|
59 |
+
state = me.state(State)
|
60 |
+
state.input = e.value
|
61 |
+
|
62 |
+
def chat_input():
|
63 |
+
state = me.state(State)
|
64 |
+
with me.box(
|
65 |
+
style=me.Style(
|
66 |
+
border_radius=16,
|
67 |
+
padding=me.Padding.all(8),
|
68 |
+
background="white",
|
69 |
+
display="flex",
|
70 |
+
width="100%",
|
71 |
+
)
|
72 |
+
):
|
73 |
+
with me.box(style=me.Style(flex_grow=1)):
|
74 |
+
me.native_textarea(
|
75 |
+
value=state.input,
|
76 |
+
placeholder="Enter a prompt",
|
77 |
+
on_blur=on_blur,
|
78 |
+
style=me.Style(
|
79 |
+
padding=me.Padding(top=16, left=16),
|
80 |
+
outline="none",
|
81 |
+
width="100%",
|
82 |
+
border=me.Border.all(me.BorderSide(style="none")),
|
83 |
+
),
|
84 |
+
)
|
85 |
+
with me.content_button(type="icon", on_click=send_prompt):
|
86 |
+
me.icon("send")
|
87 |
+
|
88 |
+
def send_prompt(e: me.ClickEvent):
|
89 |
+
state = me.state(State)
|
90 |
+
print(f"Sending prompt: {state.input}")
|
91 |
+
state.input = ""
|