Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import re
|
3 |
|
|
|
4 |
import numpy as np
|
5 |
import panel as pn
|
6 |
import tastymap as tm
|
@@ -8,11 +9,10 @@ from openai import AsyncOpenAI
|
|
8 |
|
9 |
pn.extension()
|
10 |
|
11 |
-
COLORMAP = "viridis_r"
|
12 |
-
NUM_COLORS = 8
|
13 |
-
|
14 |
|
15 |
def color_by_logprob(text, log_prob):
|
|
|
|
|
16 |
linear_prob = np.round(np.exp(log_prob) * 100, 2)
|
17 |
# select index based on probability
|
18 |
color_index = int(linear_prob // (100 / (len(colors) - 1)))
|
@@ -37,6 +37,7 @@ def custom_serializer(content):
|
|
37 |
|
38 |
|
39 |
async def respond_to_input(contents: str, user: str, instance: pn.chat.ChatInterface):
|
|
|
40 |
if api_key_input.value:
|
41 |
aclient.api_key = api_key_input.value
|
42 |
elif not os.environ["OPENAI_API_KEY"]:
|
@@ -91,13 +92,10 @@ async def respond_to_input(contents: str, user: str, instance: pn.chat.ChatInter
|
|
91 |
)
|
92 |
|
93 |
|
94 |
-
tmap = tm.cook_tmap(COLORMAP, NUM_COLORS)
|
95 |
-
colors = tmap.to_model("hex")
|
96 |
aclient = AsyncOpenAI()
|
97 |
api_key_input = pn.widgets.PasswordInput(
|
98 |
name="API Key",
|
99 |
placeholder="sk-...",
|
100 |
-
width=150,
|
101 |
)
|
102 |
system_input = pn.widgets.TextAreaInput(
|
103 |
name="System Prompt",
|
@@ -112,16 +110,15 @@ default_input = pn.widgets.TextAreaInput(
|
|
112 |
model_selector = pn.widgets.Select(
|
113 |
name="Model",
|
114 |
options=["gpt-3.5-turbo", "gpt-4"],
|
115 |
-
width=150,
|
116 |
)
|
|
|
|
|
117 |
temperature_input = pn.widgets.FloatInput(
|
118 |
-
name="Temperature", start=0, end=2, step=0.01, value=1
|
119 |
-
)
|
120 |
-
max_tokens_input = pn.widgets.IntInput(name="Max Tokens", start=0, value=256, width=100)
|
121 |
-
seed_input = pn.widgets.IntInput(name="Seed", start=0, end=100, value=0, width=100)
|
122 |
-
memory_toggle = pn.widgets.Toggle(
|
123 |
-
name="Include Memory", value=False, width=100, margin=(22, 5)
|
124 |
)
|
|
|
|
|
|
|
125 |
chat_interface = pn.chat.ChatInterface(
|
126 |
callback=respond_to_input,
|
127 |
callback_user="ChatGPT",
|
@@ -131,24 +128,22 @@ chat_interface = pn.chat.ChatInterface(
|
|
131 |
},
|
132 |
show_rerun=False,
|
133 |
)
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
chat_interface,
|
154 |
-
).servable()
|
|
|
1 |
import os
|
2 |
import re
|
3 |
|
4 |
+
import colorcet
|
5 |
import numpy as np
|
6 |
import panel as pn
|
7 |
import tastymap as tm
|
|
|
9 |
|
10 |
pn.extension()
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
def color_by_logprob(text, log_prob):
|
14 |
+
tmap = tm.cook_tmap(colormap_input.value, colors_input.value)
|
15 |
+
colors = tmap.to_model("hex")
|
16 |
linear_prob = np.round(np.exp(log_prob) * 100, 2)
|
17 |
# select index based on probability
|
18 |
color_index = int(linear_prob // (100 / (len(colors) - 1)))
|
|
|
37 |
|
38 |
|
39 |
async def respond_to_input(contents: str, user: str, instance: pn.chat.ChatInterface):
|
40 |
+
print(contents)
|
41 |
if api_key_input.value:
|
42 |
aclient.api_key = api_key_input.value
|
43 |
elif not os.environ["OPENAI_API_KEY"]:
|
|
|
92 |
)
|
93 |
|
94 |
|
|
|
|
|
95 |
aclient = AsyncOpenAI()
|
96 |
api_key_input = pn.widgets.PasswordInput(
|
97 |
name="API Key",
|
98 |
placeholder="sk-...",
|
|
|
99 |
)
|
100 |
system_input = pn.widgets.TextAreaInput(
|
101 |
name="System Prompt",
|
|
|
110 |
model_selector = pn.widgets.Select(
|
111 |
name="Model",
|
112 |
options=["gpt-3.5-turbo", "gpt-4"],
|
|
|
113 |
)
|
114 |
+
colormap_input = pn.widgets.ColorMap(name="ColorMap", options=colorcet.palette)
|
115 |
+
colors_input = pn.widgets.IntInput(name="Number of Colors", start=1, value=6)
|
116 |
temperature_input = pn.widgets.FloatInput(
|
117 |
+
name="Temperature", start=0, end=2, step=0.01, value=1
|
|
|
|
|
|
|
|
|
|
|
118 |
)
|
119 |
+
max_tokens_input = pn.widgets.IntInput(name="Max Tokens", start=0, value=256)
|
120 |
+
seed_input = pn.widgets.IntInput(name="Seed", start=0, end=100, value=0)
|
121 |
+
memory_toggle = pn.widgets.Toggle(name="Include Memory", value=False, margin=(22, 5))
|
122 |
chat_interface = pn.chat.ChatInterface(
|
123 |
callback=respond_to_input,
|
124 |
callback_user="ChatGPT",
|
|
|
128 |
},
|
129 |
show_rerun=False,
|
130 |
)
|
131 |
+
|
132 |
+
sidebar = pn.Column(
|
133 |
+
api_key_input,
|
134 |
+
system_input,
|
135 |
+
default_input,
|
136 |
+
model_selector,
|
137 |
+
colormap_input,
|
138 |
+
colors_input,
|
139 |
+
temperature_input,
|
140 |
+
max_tokens_input,
|
141 |
+
seed_input,
|
142 |
+
memory_toggle,
|
143 |
+
)
|
144 |
+
main = pn.Column(chat_interface)
|
145 |
+
template = pn.template.FastListTemplate(
|
146 |
+
sidebar=sidebar,
|
147 |
+
main=main,
|
148 |
+
)
|
149 |
+
template.show()
|
|
|
|