-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
274 lines (258 loc) · 12.8 KB
/
app.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import pynecone as pc
class alpaca_chat(pc.State):
_question: str = ""
_answer: str = ""
input = ""
# ** check box for output
code: bool = False
code_lang: str = "python"
input_enable: str = False
# ** chech for answer
thinking = False
# * generation parameters
temp: float = 2.0
num_words: int = 45
#################### UI Changing params #############################
#TODO : connect them to the ui
#################### Text Area ###############################
def set_question(self, question):
self._question = question
@pc.var
def get_question(self):
return self._question
##################### button ################################
def process_answer(self):
self.thinking = True
def get_answer(self):
#TODO : handle inputs for instsructions
# generation_config = GenerationConfig(
# temperature = float(float(self.temp) / 10),
# top_p=0.75,
# top_k=40,
# num_beams=4,
# max_new_tokens= int(self.num_words))
# self._answer = response(self._question, generation_config)
# self._answer = #TODO : change your model
## #####################
self.thinking = False
@pc.var
def view_answer(self):
return self._answer
##################### generation parameters ##################
def code_output(self):
self.code = not (self.code)
def index():
return pc.box(
pc.vstack(
# * Title
pc.center(
pc.heading(
"Alpaca-Q/A",
font_size="3.5em",
_hover={"cursor": "pointer"},
),
padding_bottom="2em",
width="75%",
#padding_right="2em",
),
pc.hstack(
pc.vstack(
# * Question spot
pc.heading("instruction", font_size="1.5em", align_items="left"),
pc.text_area(
placeholder="Ask Alpaca",
on_blur=alpaca_chat.set_question,
width="100%",
background="white",
),
pc.divider(),
pc.cond(
alpaca_chat.input_enable,
c1=pc.vstack(
pc.heading("Input", font_size="1.5em"),
pc.text_area(
placeholder="input for Question",
on_blur=alpaca_chat.set_input,
background="white",
),
width="100%",
),
),
pc.divider(),
# * waiting for answer
pc.cond(
alpaca_chat.thinking,
pc.vstack(
pc.text("Alpaca is thinking "),
pc.progress(is_indeterminate=True, width="75%"),
),
# pc.text("Alapaca is done "),
),
# * Answer spot
pc.cond(
alpaca_chat.code,
c1=pc.vstack(
pc.text("you : " + alpaca_chat.get_question,width="100%",background="white",),
pc.text("Alpaca : ",width="100%",background="white",),
pc.code_block(alpaca_chat.view_answer,width="100%",language=alpaca_chat.code_lang,),
width="100%",background="white",
),
c2=pc.vstack(
pc.text("you : " + alpaca_chat.get_question, width="100%", background="white"),
pc.text("Alpaca : " + alpaca_chat.view_answer, width="100%", background="white"), width="100%", background="white"),
),
pc.center( # * chat button
pc.button(
"Ask Alpaca",
width="100%",
on_click=[
alpaca_chat.process_answer,
alpaca_chat.get_answer,
],
background="gray",
),
),
pc.accordion(
pc.accordion_item(
pc.accordion_button(
pc.heading("Generation Settings"),
pc.accordion_icon(),
reduce_motion=True,
),
pc.accordion_panel(
pc.center(
pc.vstack(
# * unique ability
pc.hstack(
pc.center(
pc.tooltip(
pc.text(
f"Tempreture ", font_size=20
),
label="This indicates unique-ability of genereation, set high for relatively close generation",
),
pc.spacer(),
pc.slider(
default_value=2,
on_change=alpaca_chat.set_temp,
min_=1,
max_=10,
width="50%",
),
width="100%",
),
width="100%",
),
# * code output
pc.hstack(
pc.center(
pc.tooltip(
pc.text(
"Code Output", font_size=20
),
label="enable to handle generated code correctly",
),
pc.spacer(),
pc.switch(
on_change=alpaca_chat.set_code
),
width="100%",
),
width="100%",
),
# * Input enable for instruction like summarize:
pc.hstack(
pc.center(
pc.tooltip(
pc.text(
"Instruction's input - Not Working yet",
font_size=20,
),
label="Enable when your task includes inputs, ex : Summarize ",
),
pc.spacer(),
pc.switch(
on_change=alpaca_chat.set_input_enable
),
width="100%",
),
width="100%",
),
# * number of generated words
pc.hstack(
pc.center(
pc.tooltip(
pc.text(
"Max number of tokens",
font_size=20,
),
label="Max Number of generated words",
),
pc.spacer(),
pc.number_input(
defaultValue=64,
on_change=alpaca_chat.set_num_words,
width="50%",
background="white",
max_ = 250,
min_ = 10,
),
width="100%",
),
width="100%",
),
# * language output horizontal stack
pc.hstack(
pc.center(
pc.tooltip(
pc.text(
"code language", font_size=20
),
label="Write the type of language",
),
pc.spacer(),
pc.input(
defaultValue="python",
on_blur=alpaca_chat.set_code_lang,
width="50%",
background="white",
),
# pc.switch(on_change=alpaca_chat.set_code),
width="100%",
),
width="100%",
),
pc.alert(
pc.alert_icon(),
pc.alert_title(
"Refresh if it took longer than intended, don't worry, your answer'll be there"
),
status="warning",
),
),
width="100%",
),
),
),
width="100%",
),
width="100%",
padding_bottom="4em",
),
width="80%",
align_items="bottom",
),
width="100%",
height="100%",
padding_top="2em",
# background="radial-gradient(circle at 22% 11%,rgba(62, 180, 137,.20),hsla(0,0%,100%,0) 19%),radial-gradient(circle at 82% 25%,rgba(33,150,243,.18),hsla(0,0%,100%,0) 35%),radial-gradient(circle at 25% 61%,rgba(250, 128, 114, .28),hsla(0,0%,100%,0) 55%)",
# background = 'white',
),
width="100%",
height="100%",
padding_top="2em",
background="radial-gradient(circle at 22% 11%,rgba(62, 180, 137,.20),hsla(0,0%,100%,0) 19%),radial-gradient(circle at 82% 25%,rgba(33,150,243,.18),hsla(0,0%,100%,0) 35%),radial-gradient(circle at 25% 61%,rgba(250, 128, 114, .28),hsla(0,0%,100%,0) 55%)",
)
app = pc.App(state=alpaca_chat)
app.add_page(index)
app.compile()