Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ system_message = {
|
|
13 |
|
14 |
# Function to reset the chat
|
15 |
def reset_chat():
|
16 |
-
return [], "New Chat"
|
17 |
|
18 |
# Function to handle the questionnaire submission
|
19 |
def submit_questionnaire(name, age, location, gender, ethnicity, height, weight,
|
@@ -87,7 +87,7 @@ with gr.Blocks() as demo:
|
|
87 |
weight = gr.Number(label="Weight (kg)", value=70, minimum=20, maximum=200)
|
88 |
|
89 |
with gr.Column():
|
90 |
-
submit_btn = gr.Button("Submit
|
91 |
reset_btn = gr.Button("Reset Chat")
|
92 |
|
93 |
# Questionnaire with fashion-related questions
|
@@ -95,16 +95,62 @@ with gr.Blocks() as demo:
|
|
95 |
color_palette = gr.Radio(label="What color palette do you wear often?", choices=["Neutrals", "Bright Colors", "Pastels", "Dark Shades"])
|
96 |
everyday_style = gr.Radio(label="How would you describe your everyday style?", choices=["Relaxed", "Trendy", "Elegant", "Bold"])
|
97 |
|
98 |
-
#
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
# Connect the buttons to their respective functions
|
103 |
-
output_message = gr.Textbox(label="Output Message") # Define an output component
|
104 |
submit_btn.click(submit_questionnaire, inputs=[name, age, location, gender, ethnicity, height, weight,
|
105 |
-
style_preference, color_palette, everyday_style], outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
-
reset_btn.click(reset_chat, outputs=[chatbox, output_message]) # Corrected outputs
|
108 |
user_input.submit(chat, inputs=[user_input, chatbox], outputs=[chatbox, user_input])
|
109 |
|
110 |
# Run the app
|
|
|
13 |
|
14 |
# Function to reset the chat
|
15 |
def reset_chat():
|
16 |
+
return [], "New Chat"
|
17 |
|
18 |
# Function to handle the questionnaire submission
|
19 |
def submit_questionnaire(name, age, location, gender, ethnicity, height, weight,
|
|
|
87 |
weight = gr.Number(label="Weight (kg)", value=70, minimum=20, maximum=200)
|
88 |
|
89 |
with gr.Column():
|
90 |
+
submit_btn = gr.Button("Submit Inputs")
|
91 |
reset_btn = gr.Button("Reset Chat")
|
92 |
|
93 |
# Questionnaire with fashion-related questions
|
|
|
95 |
color_palette = gr.Radio(label="What color palette do you wear often?", choices=["Neutrals", "Bright Colors", "Pastels", "Dark Shades"])
|
96 |
everyday_style = gr.Radio(label="How would you describe your everyday style?", choices=["Relaxed", "Trendy", "Elegant", "Bold"])
|
97 |
|
98 |
+
# Additional fashion-related questions
|
99 |
+
fashion_questions = [
|
100 |
+
("What do you prioritize when choosing an outfit?", ["Comfort", "Style", "Affordability", "Brand"]),
|
101 |
+
("How often do you experiment with new trends?", ["Always", "Sometimes", "Rarely", "Never"]),
|
102 |
+
("What kind of accessories do you usually wear?", ["Watches", "Rings", "Necklaces", "Bracelets", "Earrings"]),
|
103 |
+
("Do you follow fashion trends?", ["Always", "Sometimes", "Never"]),
|
104 |
+
("How satisfied are you with your wardrobe?", ["Very Satisfied", "Satisfied", "Neutral", "Unsatisfied"]),
|
105 |
+
("Do you consider your style unique?", ["Yes", "No"]),
|
106 |
+
("How confident do you feel in your style?", ["Very Confident", "Somewhat Confident", "Not Confident"]),
|
107 |
+
("Where do you look for fashion inspiration?", ["Social Media", "Fashion Magazines", "Friends", "Other"]),
|
108 |
+
("Do you have specific attire for special occasions?", ["Yes", "No"]),
|
109 |
+
("Do you wear gender-neutral clothing?", ["Yes", "No"]),
|
110 |
+
("Which clothing materials do you prefer?", ["Cotton", "Silk", "Denim", "Synthetic", "Wool"]),
|
111 |
+
("How important is sustainability in your fashion choices?", ["Very Important", "Somewhat Important", "Not Important"]),
|
112 |
+
("Do you prefer shopping online or in physical stores?", ["Online", "Physical Stores"]),
|
113 |
+
("How often do you update your wardrobe?", ["Seasonally", "Every Few Months", "Once a Year", "Rarely"]),
|
114 |
+
("Do you participate in clothing swaps or second-hand shopping?", ["Yes", "No"]),
|
115 |
+
]
|
116 |
+
|
117 |
+
# Create a button for filling the questionnaire
|
118 |
+
fill_questionnaire_btn = gr.Button("Fill Questionnaire")
|
119 |
+
|
120 |
+
# Output message for questionnaire submission
|
121 |
+
questionnaire_output = gr.Textbox(label="Questionnaire Submission", interactive=False)
|
122 |
+
|
123 |
+
# Function to collect all questionnaire responses
|
124 |
+
def collect_questionnaire_responses():
|
125 |
+
# Store questionnaire responses in a DataFrame
|
126 |
+
questionnaire_data = {
|
127 |
+
"Style Preference": style_preference.value,
|
128 |
+
"Color Palette": color_palette.value,
|
129 |
+
"Everyday Style": everyday_style.value
|
130 |
+
}
|
131 |
+
|
132 |
+
# Append additional responses
|
133 |
+
for question, choices in fashion_questions:
|
134 |
+
questionnaire_data[question] = gr.Radio(label=question, choices=choices).value
|
135 |
+
|
136 |
+
df = pd.DataFrame([questionnaire_data]) # Create DataFrame from dictionary
|
137 |
+
|
138 |
+
# Append to CSV file
|
139 |
+
df.to_csv("questionnaire_responses.csv", mode='a', header=not pd.io.common.file_exists("questionnaire_responses.csv"), index=False)
|
140 |
+
|
141 |
+
return "Thank you for completing the questionnaire!"
|
142 |
|
143 |
# Connect the buttons to their respective functions
|
|
|
144 |
submit_btn.click(submit_questionnaire, inputs=[name, age, location, gender, ethnicity, height, weight,
|
145 |
+
style_preference, color_palette, everyday_style], outputs=questionnaire_output)
|
146 |
+
|
147 |
+
fill_questionnaire_btn.click(collect_questionnaire_responses, outputs=questionnaire_output)
|
148 |
+
|
149 |
+
reset_btn.click(reset_chat, outputs=[gr.Chatbot(type='messages'), "title"])
|
150 |
+
|
151 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
152 |
+
chatbox = gr.Chatbot(type='messages')
|
153 |
|
|
|
154 |
user_input.submit(chat, inputs=[user_input, chatbox], outputs=[chatbox, user_input])
|
155 |
|
156 |
# Run the app
|