Spaces:
Build error
Build error
File size: 6,862 Bytes
0adb98d c36c5ac 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d c36c5ac 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 c36c5ac 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d 9322e67 0adb98d | 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 | import gradio as gr
from definitions import SIZES_PER_CATEGORY
def update_main_categories(main):
if isinstance(SIZES_PER_CATEGORY[main], list):
return (
main,
"",
"",
gr.Dropdown(list(SIZES_PER_CATEGORY[main]), label="Size", interactive=True),
)
return (
main,
"",
"",
gr.Dropdown(
list(SIZES_PER_CATEGORY[main].keys()),
label="Size",
interactive=False,
),
)
def update_sub_categories(main, sub):
if isinstance(SIZES_PER_CATEGORY[main][sub], list):
return (
main,
sub,
"",
gr.Dropdown(
list(SIZES_PER_CATEGORY[main][sub]), label="Size", interactive=True
),
)
return (
main,
sub,
"",
gr.Dropdown(
list(SIZES_PER_CATEGORY[main][sub].keys()),
label="Size",
interactive=False,
),
)
def update_sub_sub_categories(main, sub, sub_sub):
if isinstance(SIZES_PER_CATEGORY[main][sub][sub_sub], list):
return (
main,
sub,
sub_sub,
gr.Dropdown(
list(SIZES_PER_CATEGORY[main][sub][sub_sub]),
label="Size",
interactive=True,
),
)
return (
main,
sub,
sub_sub,
gr.Dropdown(
list(SIZES_PER_CATEGORY[main][sub][sub_sub].keys()),
label="Size",
interactive=False,
),
)
def submit_form(
title,
description,
condition,
main_category,
sub_category,
sub_sub_category,
size,
color,
hashtags,
designer_names,
followerno,
user_score,
):
print(
f"Title: {title}, Description: {description}, Condition: {condition}, hashtags: {hashtags}, designer: {designer_names}, Main Category: {main_category}, Sub:{sub_category}, sub_sub:{sub_sub_category}, Size: {size}, Color: {color}, Followers: {followerno}, User Score: {user_score}"
)
with gr.Blocks(theme="argilla/argilla-theme", title="Grailed Price Predictor") as demo:
global size_text_box
gr.HTML(
"""
<h1 style="text-align: center;">Grailed Price Predictor</h1>
<p>Welcome to our Grailed Price Prediction Model! This project, developed for the ID2223 course,
demonstrates how modern machine learning systems can be effectively implemented using feature stores and serverless computing.
To get started, simply fill out the form and click "Submit."</p>
"""
)
main_category = gr.State("")
sub_category = gr.State("")
sub_sub_category = gr.State("")
with gr.Group():
title_text_box = gr.Textbox(label="Title")
description_text_area = gr.TextArea(label="Description")
condition_dropdown = gr.Dropdown(
["new", "gently used", "used", "worn"],
label="Condition",
info="The condition of your item.",
interactive=True,
)
with gr.Row():
with gr.Column():
@gr.render(inputs=[main_category, sub_category, sub_sub_category])
def show_categories(main, sub, sub_sub):
global size_text_box
main_dropdown = gr.Dropdown(
list(SIZES_PER_CATEGORY.keys()),
label="Main Category",
value=main,
interactive=True,
)
main_dropdown.change(
update_main_categories,
main_dropdown,
[main_category, sub_category, sub_sub_category, size_text_box],
)
if not main or isinstance(SIZES_PER_CATEGORY[main], list):
return
sub_dropdown = gr.Dropdown(
list(SIZES_PER_CATEGORY[main].keys()),
label="Sub Category",
interactive=True,
value=sub,
)
sub_dropdown.change(
update_sub_categories,
[main_dropdown, sub_dropdown],
[main_category, sub_category, sub_sub_category, size_text_box],
)
if not sub or isinstance(SIZES_PER_CATEGORY[main][sub], list):
return
sub_sub_dropdown = gr.Dropdown(
list(SIZES_PER_CATEGORY[main][sub].keys()),
label="Sub Sub Category",
interactive=True,
value=sub_sub,
)
sub_dropdown.change(
update_sub_sub_categories,
[main_dropdown, sub_dropdown, sub_sub_dropdown],
[main_category, sub_category, sub_sub_category, size_text_box],
)
size_text_box = gr.Dropdown(
label="Size",
interactive=False,
)
color_text_box = gr.Textbox(label="Color")
with gr.Row():
with gr.Column():
hashtags_text_box = gr.Textbox(label="Hashtags")
@gr.render(inputs=hashtags_text_box)
def show_hashtags(textbox):
if not textbox:
return
for i, hashtag in enumerate(textbox.split(" ")):
gr.Textbox(label=f"Hashtag #{i+1}", value=hashtag)
with gr.Column():
designer_names_text_box = gr.Textbox(label="Designer Names")
@gr.render(inputs=designer_names_text_box)
def show_designer_names(textbox):
if not textbox:
return
for i, designer_name in enumerate(textbox.split(" ")):
gr.Textbox(label=f"Designer Name #{i+1}", value=designer_name)
with gr.Row():
followernoNumber = gr.Number(label="Number of Followers")
userScoreNumber = gr.Number(label="Your User Score")
submitButton = gr.Button("Submit")
submitButton.click(
submit_form,
[
title_text_box,
description_text_area,
condition_dropdown,
main_category,
sub_category,
sub_sub_category,
size_text_box,
color_text_box,
hashtags_text_box,
followernoNumber,
userScoreNumber,
],
)
if __name__ == "__main__":
demo.launch()
|