Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,8 +31,8 @@ RANDOM_NAME_QUERY = """
|
|
31 |
SELECT name, count,
|
32 |
CASE
|
33 |
WHEN female_percent >= 0.2 AND female_percent <= 0.8 AND male_percent >= 0.2 AND male_percent <= 0.8 THEN 'unisex'
|
34 |
-
WHEN female_percent > 0.
|
35 |
-
WHEN male_percent > 0.
|
36 |
END AS gender
|
37 |
FROM (
|
38 |
SELECT
|
@@ -99,6 +99,9 @@ class NameChronicles:
|
|
99 |
self.db_path = Path("data/names.db")
|
100 |
|
101 |
# Main
|
|
|
|
|
|
|
102 |
self.holoviews_pane = pn.pane.HoloViews(
|
103 |
min_height=675, sizing_mode="stretch_both"
|
104 |
)
|
@@ -135,7 +138,7 @@ class NameChronicles:
|
|
135 |
)
|
136 |
self.count_range = pn.widgets.IntRangeSlider(
|
137 |
name="Peak Count Range",
|
138 |
-
value=(
|
139 |
start=0,
|
140 |
end=100000,
|
141 |
step=1000,
|
@@ -180,8 +183,9 @@ class NameChronicles:
|
|
180 |
name="Parse and Add Names",
|
181 |
button_style="outline",
|
182 |
button_type="primary",
|
183 |
-
disabled=
|
184 |
)
|
|
|
185 |
pn.state.onload(self._initialize_database)
|
186 |
|
187 |
# Database Methods
|
@@ -281,15 +285,18 @@ class NameChronicles:
|
|
281 |
name_pattern = "%"
|
282 |
else:
|
283 |
name_pattern = name_pattern.replace("*", "%")
|
|
|
|
|
|
|
284 |
count_range = self.count_range.value
|
285 |
gender_select = self.gender_select.value.lower()
|
286 |
random_names = (
|
287 |
self.conn.execute(
|
288 |
RANDOM_NAME_QUERY, [name_pattern, *count_range, gender_select]
|
289 |
-
)
|
290 |
-
.fetch_df()["name"]
|
291 |
.tolist()
|
292 |
)
|
|
|
293 |
if random_names:
|
294 |
for i in range(len(random_names)):
|
295 |
random_name = random_names[i]
|
@@ -345,10 +352,12 @@ class NameChronicles:
|
|
345 |
f"One sentence reply to {contents!r} or concisely suggest other relevant names; "
|
346 |
f"if no name is provided use {self.names_choice.value[-1]!r}."
|
347 |
)
|
|
|
348 |
self.last_ai_output = await self.conversation_chain.apredict(
|
349 |
input=prompt,
|
350 |
callbacks=[self.callback_handler],
|
351 |
)
|
|
|
352 |
self.llm_use_counter += 1
|
353 |
|
354 |
async def _parse_ai_output(self, _):
|
@@ -427,9 +436,6 @@ class NameChronicles:
|
|
427 |
tooltips=[("Name", "@name"), ("Year", "@year"), ("Count", "@count")],
|
428 |
)
|
429 |
self._name_indices = {}
|
430 |
-
scatter_cycle = hv.Cycle("Category10")
|
431 |
-
curve_cycle = hv.Cycle("Category10")
|
432 |
-
label_cycle = hv.Cycle("Category10")
|
433 |
for i, (name, df_name) in enumerate(self.df.groupby("name")):
|
434 |
df_name_total = df_name.groupby(
|
435 |
["name", "year", "male", "female"], as_index=False
|
@@ -453,7 +459,7 @@ class NameChronicles:
|
|
453 |
self._scatter_nd_overlay[i] = hv.Scatter(
|
454 |
df_name_total, ["year"], ["count", "male", "female", "name"], label=name
|
455 |
).opts(
|
456 |
-
color=scatter_cycle,
|
457 |
size=4,
|
458 |
alpha=0.15,
|
459 |
marker="y",
|
@@ -464,7 +470,7 @@ class NameChronicles:
|
|
464 |
self._curve_nd_overlay[i] = hv.Curve(
|
465 |
df_name_total, ["year"], ["count"], label=name
|
466 |
).opts(
|
467 |
-
color=curve_cycle,
|
468 |
tools=["tap"],
|
469 |
line_width=3,
|
470 |
)
|
@@ -473,7 +479,7 @@ class NameChronicles:
|
|
473 |
).opts(
|
474 |
text_align="right",
|
475 |
text_baseline="bottom",
|
476 |
-
text_color=label_cycle,
|
477 |
)
|
478 |
self._name_indices[i] = name
|
479 |
self.selection.source = self._curve_nd_overlay
|
|
|
31 |
SELECT name, count,
|
32 |
CASE
|
33 |
WHEN female_percent >= 0.2 AND female_percent <= 0.8 AND male_percent >= 0.2 AND male_percent <= 0.8 THEN 'unisex'
|
34 |
+
WHEN female_percent > 0.5 THEN 'female'
|
35 |
+
WHEN male_percent > 0.5 THEN 'male'
|
36 |
END AS gender
|
37 |
FROM (
|
38 |
SELECT
|
|
|
99 |
self.db_path = Path("data/names.db")
|
100 |
|
101 |
# Main
|
102 |
+
self.scatter_cycle = hv.Cycle("Category10")
|
103 |
+
self.curve_cycle = hv.Cycle("Category10")
|
104 |
+
self.label_cycle = hv.Cycle("Category10")
|
105 |
self.holoviews_pane = pn.pane.HoloViews(
|
106 |
min_height=675, sizing_mode="stretch_both"
|
107 |
)
|
|
|
138 |
)
|
139 |
self.count_range = pn.widgets.IntRangeSlider(
|
140 |
name="Peak Count Range",
|
141 |
+
value=(0, 100000),
|
142 |
start=0,
|
143 |
end=100000,
|
144 |
step=1000,
|
|
|
183 |
name="Parse and Add Names",
|
184 |
button_style="outline",
|
185 |
button_type="primary",
|
186 |
+
disabled=True,
|
187 |
)
|
188 |
+
self.last_ai_output = None
|
189 |
pn.state.onload(self._initialize_database)
|
190 |
|
191 |
# Database Methods
|
|
|
285 |
name_pattern = "%"
|
286 |
else:
|
287 |
name_pattern = name_pattern.replace("*", "%")
|
288 |
+
if not name_pattern.startswith("%"):
|
289 |
+
name_pattern = name_pattern.title()
|
290 |
+
|
291 |
count_range = self.count_range.value
|
292 |
gender_select = self.gender_select.value.lower()
|
293 |
random_names = (
|
294 |
self.conn.execute(
|
295 |
RANDOM_NAME_QUERY, [name_pattern, *count_range, gender_select]
|
296 |
+
).fetch_df()["name"]
|
|
|
297 |
.tolist()
|
298 |
)
|
299 |
+
print(len(random_names))
|
300 |
if random_names:
|
301 |
for i in range(len(random_names)):
|
302 |
random_name = random_names[i]
|
|
|
352 |
f"One sentence reply to {contents!r} or concisely suggest other relevant names; "
|
353 |
f"if no name is provided use {self.names_choice.value[-1]!r}."
|
354 |
)
|
355 |
+
print(prompt)
|
356 |
self.last_ai_output = await self.conversation_chain.apredict(
|
357 |
input=prompt,
|
358 |
callbacks=[self.callback_handler],
|
359 |
)
|
360 |
+
self.parse_ai_button.disabled = False
|
361 |
self.llm_use_counter += 1
|
362 |
|
363 |
async def _parse_ai_output(self, _):
|
|
|
436 |
tooltips=[("Name", "@name"), ("Year", "@year"), ("Count", "@count")],
|
437 |
)
|
438 |
self._name_indices = {}
|
|
|
|
|
|
|
439 |
for i, (name, df_name) in enumerate(self.df.groupby("name")):
|
440 |
df_name_total = df_name.groupby(
|
441 |
["name", "year", "male", "female"], as_index=False
|
|
|
459 |
self._scatter_nd_overlay[i] = hv.Scatter(
|
460 |
df_name_total, ["year"], ["count", "male", "female", "name"], label=name
|
461 |
).opts(
|
462 |
+
color=self.scatter_cycle,
|
463 |
size=4,
|
464 |
alpha=0.15,
|
465 |
marker="y",
|
|
|
470 |
self._curve_nd_overlay[i] = hv.Curve(
|
471 |
df_name_total, ["year"], ["count"], label=name
|
472 |
).opts(
|
473 |
+
color=self.curve_cycle,
|
474 |
tools=["tap"],
|
475 |
line_width=3,
|
476 |
)
|
|
|
479 |
).opts(
|
480 |
text_align="right",
|
481 |
text_baseline="bottom",
|
482 |
+
text_color=self.label_cycle,
|
483 |
)
|
484 |
self._name_indices[i] = name
|
485 |
self.selection.source = self._curve_nd_overlay
|