Spaces:
Runtime error
Runtime error
File size: 4,933 Bytes
6739f59 |
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 |
import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
from dash import html
from dash_iconify import DashIconify
def template_card(title, content, image_url=None, id=None):
return dmc.Col(
dmc.Card(
children=[
dmc.CardSection(
dmc.Image(
src=image_url
or "https://images.unsplash.com/photo-1460925895917-afdab827c52f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2426&q=80",
height=160,
)
),
dmc.Group(
[
dmc.Text(title, weight=500),
# dmc.Badge("On Sale", color="red", variant="light"),
],
position="apart",
mt="md",
mb="xs",
),
dmc.Text(
content
or "Ask RetailGPT to analyze the performance of your store and get a detailed report.",
size="sm",
color="dimmed",
),
dmc.Button(
"Ask RetailGPT",
id=f"template-ask-button-{id}",
variant="light",
color="blue",
fullWidth=True,
mt="md",
radius="md",
rightIcon=DashIconify(
icon="material-symbols:send-rounded"
),
),
],
withBorder=True,
shadow="sm",
radius="md",
),
span=3,
)
def template_menu_item(prompt, id=None):
return dmc.MenuItem(prompt, id=f"template-ask-button-{id}", n_clicks=0)
def get_template_menu_items():
id_list = [0, 1, 2, 3]
prompts = [
"How did my store perform during the last seasonal sales?",
"What were the best weeks of the current year?",
"What were my best-selling products last week?",
"Show me the total sales for each store in the last 3 months",
]
items = [
template_menu_item(prompt=prompt, id=ids)
for prompt, ids in zip(prompts, id_list)
]
return items
def get_template_cards():
titles = [
"See your store performance",
"Understand your customers",
"Find your best-selling products",
"Compare your stores",
]
id_list = [0, 1, 2, 3]
contents = [
"How did my store perform during the last seasonal sales ?",
"What were the best weeks of the current year ?",
"What were my best-selling products last week?",
"Show me the total sales for each store in the last 3 months",
]
urls = [
"https://images.unsplash.com/photo-1441986300917-64674bd600d8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2670&q=80",
"https://images.unsplash.com/photo-1556740772-1a741367b93e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2670&q=80",
"https://images.unsplash.com/photo-1511556820780-d912e42b4980?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1287&q=80",
"https://images.unsplash.com/photo-1526628953301-3e589a6a8b74?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2306&q=80",
]
cards = [
template_card(title=title, content=content, image_url=url, id=ids)
for title, content, url, ids in zip(titles, contents, urls, id_list)
]
template_cards = dmc.Grid(
cards,
grow=False,
gutter="xl",
justify="space-between",
align="center",
)
return template_cards
def history_item(prompt: str, response: str):
return dbc.ListGroupItem(
[
html.Div(
[
html.H5(
"AI Generated Response",
className="mb-1",
),
html.Small(
"Yay!",
className="text-success",
),
],
className="d-flex w-100 justify-content-between",
),
html.P(
[
html.Span("User: ", className="text-muted"),
html.Span(prompt),
],
className="mb-1",
),
html.P(
[
html.Span("AI: ", className="text-muted"),
html.Span(response),
],
className="mb-1",
),
],
action=True,
style={"cursor": "pointer"},
)
|