CoolFace
Apppublic

EPark25/ID2223-Project-UI

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py217 linesDownload Raw Back to root
1import gradio as gr2from definitions import SIZES_PER_CATEGORY3 4 5def update_main_categories(main):6    if isinstance(SIZES_PER_CATEGORY[main], list):7        return (8            main,9            "",10            "",11            gr.Dropdown(list(SIZES_PER_CATEGORY[main]), label="Size", interactive=True),12        )13    return (14        main,15        "",16        "",17        gr.Dropdown(18            list(SIZES_PER_CATEGORY[main].keys()),19            label="Size",20            interactive=False,21        ),22    )23 24 25def update_sub_categories(main, sub):26    if isinstance(SIZES_PER_CATEGORY[main][sub], list):27        return (28            main,29            sub,30            "",31            gr.Dropdown(32                list(SIZES_PER_CATEGORY[main][sub]), label="Size", interactive=True33            ),34        )35    return (36        main,37        sub,38        "",39        gr.Dropdown(40            list(SIZES_PER_CATEGORY[main][sub].keys()),41            label="Size",42            interactive=False,43        ),44    )45 46 47def update_sub_sub_categories(main, sub, sub_sub):48    if isinstance(SIZES_PER_CATEGORY[main][sub][sub_sub], list):49        return (50            main,51            sub,52            sub_sub,53            gr.Dropdown(54                list(SIZES_PER_CATEGORY[main][sub][sub_sub]),55                label="Size",56                interactive=True,57            ),58        )59    return (60        main,61        sub,62        sub_sub,63        gr.Dropdown(64            list(SIZES_PER_CATEGORY[main][sub][sub_sub].keys()),65            label="Size",66            interactive=False,67        ),68    )69 70 71def submit_form(72    title,73    description,74    condition,75    main_category,76    sub_category,77    sub_sub_category,78    size,79    color,80    hashtags,81    designer_names,82    followerno,83    user_score,84):85    print(86        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}"87    )88 89 90with gr.Blocks(theme="argilla/argilla-theme", title="Grailed Price Predictor") as demo:91    global size_text_box92    gr.HTML(93        """94    <h1 style="text-align: center;">Grailed Price Predictor</h1>95    <p>Welcome to our Grailed Price Prediction Model! This project, developed for the ID2223 course,96     demonstrates how modern machine learning systems can be effectively implemented using feature stores and serverless computing.97     To get started, simply fill out the form and click "Submit."</p>98    """99    )100 101    main_category = gr.State("")102    sub_category = gr.State("")103    sub_sub_category = gr.State("")104 105    with gr.Group():106        title_text_box = gr.Textbox(label="Title")107        description_text_area = gr.TextArea(label="Description")108 109        condition_dropdown = gr.Dropdown(110            ["new", "gently used", "used", "worn"],111            label="Condition",112            info="The condition of your item.",113            interactive=True,114        )115 116        with gr.Row():117            with gr.Column():118 119                @gr.render(inputs=[main_category, sub_category, sub_sub_category])120                def show_categories(main, sub, sub_sub):121                    global size_text_box122                    main_dropdown = gr.Dropdown(123                        list(SIZES_PER_CATEGORY.keys()),124                        label="Main Category",125                        value=main,126                        interactive=True,127                    )128                    main_dropdown.change(129                        update_main_categories,130                        main_dropdown,131                        [main_category, sub_category, sub_sub_category, size_text_box],132                    )133 134                    if not main or isinstance(SIZES_PER_CATEGORY[main], list):135                        return136 137                    sub_dropdown = gr.Dropdown(138                        list(SIZES_PER_CATEGORY[main].keys()),139                        label="Sub Category",140                        interactive=True,141                        value=sub,142                    )143                    sub_dropdown.change(144                        update_sub_categories,145                        [main_dropdown, sub_dropdown],146                        [main_category, sub_category, sub_sub_category, size_text_box],147                    )148 149                    if not sub or isinstance(SIZES_PER_CATEGORY[main][sub], list):150                        return151 152                    sub_sub_dropdown = gr.Dropdown(153                        list(SIZES_PER_CATEGORY[main][sub].keys()),154                        label="Sub Sub Category",155                        interactive=True,156                        value=sub_sub,157                    )158                    sub_dropdown.change(159                        update_sub_sub_categories,160                        [main_dropdown, sub_dropdown, sub_sub_dropdown],161                        [main_category, sub_category, sub_sub_category, size_text_box],162                    )163 164            size_text_box = gr.Dropdown(165                label="Size",166                interactive=False,167            )168 169        color_text_box = gr.Textbox(label="Color")170 171        with gr.Row():172            with gr.Column():173                hashtags_text_box = gr.Textbox(label="Hashtags")174 175                @gr.render(inputs=hashtags_text_box)176                def show_hashtags(textbox):177                    if not textbox:178                        return179                    for i, hashtag in enumerate(textbox.split(" ")):180                        gr.Textbox(label=f"Hashtag #{i+1}", value=hashtag)181 182            with gr.Column():183                designer_names_text_box = gr.Textbox(label="Designer Names")184 185                @gr.render(inputs=designer_names_text_box)186                def show_designer_names(textbox):187                    if not textbox:188                        return189                    for i, designer_name in enumerate(textbox.split(" ")):190                        gr.Textbox(label=f"Designer Name #{i+1}", value=designer_name)191 192        with gr.Row():193            followernoNumber = gr.Number(label="Number of Followers")194            userScoreNumber = gr.Number(label="Your User Score")195 196        submitButton = gr.Button("Submit")197        submitButton.click(198            submit_form,199            [200                title_text_box,201                description_text_area,202                condition_dropdown,203                main_category,204                sub_category,205                sub_sub_category,206                size_text_box,207                color_text_box,208                hashtags_text_box,209                followernoNumber,210                userScoreNumber,211            ],212        )213 214 215if __name__ == "__main__":216    demo.launch()217