Update app.py
Browse files
app.py
CHANGED
@@ -8,21 +8,28 @@ client = Groq(api_key="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"
|
|
8 |
# Define the system message for the model
|
9 |
system_message = {
|
10 |
"role": "system",
|
11 |
-
"content": "You are an experienced Fashion designer who
|
12 |
}
|
13 |
|
14 |
# Function to reset the chat
|
15 |
def reset_chat():
|
16 |
return [], "New Chat"
|
17 |
|
18 |
-
# Function to handle questionnaire submission
|
19 |
-
def submit_questionnaire(name, age, gender,
|
|
|
20 |
# Store questionnaire responses in a DataFrame
|
21 |
questionnaire_data = {
|
22 |
"Name": name,
|
23 |
"Age": age,
|
|
|
24 |
"Gender": gender,
|
25 |
-
"
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
|
28 |
df = pd.DataFrame([questionnaire_data]) # Create DataFrame from dictionary
|
@@ -33,18 +40,10 @@ def submit_questionnaire(name, age, gender, location):
|
|
33 |
return "Thank you for completing the questionnaire!"
|
34 |
|
35 |
# Function to handle chat
|
36 |
-
def chat(user_input, messages
|
37 |
if user_input:
|
38 |
-
#
|
39 |
-
user_profile_string = (
|
40 |
-
f"User profile: Name: {name}, Age: {age}, Location: {location}, "
|
41 |
-
f"Gender: {gender}"
|
42 |
-
)
|
43 |
-
|
44 |
-
# Prepare messages for the API call, including the profile and the conversation history
|
45 |
messages.append({"role": "user", "content": user_input})
|
46 |
-
messages.append(system_message)
|
47 |
-
messages.append({"role": "user", "content": user_profile_string})
|
48 |
|
49 |
try:
|
50 |
# Generate a response from the Groq API
|
@@ -83,20 +82,47 @@ with gr.Blocks() as demo:
|
|
83 |
age = gr.Number(label="Age", value=25, minimum=1, maximum=100)
|
84 |
location = gr.Textbox(label="Location")
|
85 |
gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
|
|
|
|
|
|
|
|
|
|
|
86 |
submit_btn = gr.Button("Submit Questionnaire")
|
87 |
reset_btn = gr.Button("Reset Chat")
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
# Chat functionality
|
90 |
chatbox = gr.Chatbot(type='messages')
|
91 |
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
92 |
|
93 |
-
# Output message for feedback
|
94 |
-
output_message = gr.Textbox(label="Output Message", interactive=False)
|
95 |
-
|
96 |
# Connect the buttons to their respective functions
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
100 |
|
101 |
# Run the app
|
102 |
demo.launch()
|
|
|
8 |
# Define the system message for the model
|
9 |
system_message = {
|
10 |
"role": "system",
|
11 |
+
"content": "You are an experienced Fashion designer who starts conversation with proper greeting, giving valuable and catchy fashion advice and suggestions, stays to the point and precise, asks questions only if the user has any concerns over your provided suggestions."
|
12 |
}
|
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,
|
20 |
+
style_preference, color_palette, everyday_style):
|
21 |
# Store questionnaire responses in a DataFrame
|
22 |
questionnaire_data = {
|
23 |
"Name": name,
|
24 |
"Age": age,
|
25 |
+
"Location": location,
|
26 |
"Gender": gender,
|
27 |
+
"Ethnicity": ethnicity,
|
28 |
+
"Height": height,
|
29 |
+
"Weight": weight,
|
30 |
+
"Style Preference": style_preference,
|
31 |
+
"Color Palette": color_palette,
|
32 |
+
"Everyday Style": everyday_style
|
33 |
}
|
34 |
|
35 |
df = pd.DataFrame([questionnaire_data]) # Create DataFrame from dictionary
|
|
|
40 |
return "Thank you for completing the questionnaire!"
|
41 |
|
42 |
# Function to handle chat
|
43 |
+
def chat(user_input, messages):
|
44 |
if user_input:
|
45 |
+
# Prepare messages for the API call
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
messages.append({"role": "user", "content": user_input})
|
|
|
|
|
47 |
|
48 |
try:
|
49 |
# Generate a response from the Groq API
|
|
|
82 |
age = gr.Number(label="Age", value=25, minimum=1, maximum=100)
|
83 |
location = gr.Textbox(label="Location")
|
84 |
gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
|
85 |
+
ethnicity = gr.Radio(label="Ethnicity", choices=["Asian", "Black", "Hispanic", "White", "Other"])
|
86 |
+
height = gr.Number(label="Height (cm)", value=170, minimum=50, maximum=250)
|
87 |
+
weight = gr.Number(label="Weight (kg)", value=70, minimum=20, maximum=200)
|
88 |
+
|
89 |
+
with gr.Column():
|
90 |
submit_btn = gr.Button("Submit Questionnaire")
|
91 |
reset_btn = gr.Button("Reset Chat")
|
92 |
|
93 |
+
# Questionnaire with fashion-related questions
|
94 |
+
style_preference = gr.Radio(label="Which style do you prefer the most?", choices=["Casual", "Formal", "Streetwear", "Athleisure", "Baggy"])
|
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?", ["Yes", "No"]),
|
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 |
+
]
|
111 |
+
|
112 |
+
for question, choices in fashion_questions:
|
113 |
+
gr.Radio(label=question, choices=choices)
|
114 |
+
|
115 |
# Chat functionality
|
116 |
chatbox = gr.Chatbot(type='messages')
|
117 |
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
118 |
|
|
|
|
|
|
|
119 |
# Connect the buttons to their respective functions
|
120 |
+
output_message = gr.Textbox(label="Output Message") # Define an output component
|
121 |
+
submit_btn.click(submit_questionnaire, inputs=[name, age, location, gender, ethnicity, height, weight,
|
122 |
+
style_preference, color_palette, everyday_style], outputs=output_message)
|
123 |
+
|
124 |
+
reset_btn.click(reset_chat, outputs=[chatbox, "title"])
|
125 |
+
user_input.submit(chat, inputs=[user_input, chatbox], outputs=[chatbox, user_input])
|
126 |
|
127 |
# Run the app
|
128 |
demo.launch()
|