Spaces:
Build error
Build error
Download app.py from EPark25/ID2223-Project-UI: direct link, hf CLI and curl.
- Browser
- Download file 6.86 kB
-
https://huggingface.co/spaces/EPark25/ID2223-Project-UI/resolve/main/app.py
- Command line
-
hf download hf://spaces/EPark25/ID2223-Project-UI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/EPark25/ID2223-Project-UI/resolve/main/app.py
6.86 kB
| 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(): | |
| 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") | |
| 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") | |
| 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() | |