Update app.py
Browse files
app.py
CHANGED
@@ -8,23 +8,21 @@ 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
|
12 |
}
|
13 |
|
14 |
# Function to reset the chat
|
15 |
def reset_chat():
|
16 |
return [], "New Chat"
|
17 |
|
18 |
-
# Function to handle
|
19 |
-
def submit_questionnaire(name, age,
|
20 |
-
# Store
|
21 |
questionnaire_data = {
|
22 |
"Name": name,
|
23 |
"Age": age,
|
24 |
-
"Location": location,
|
25 |
"Gender": gender,
|
26 |
-
"
|
27 |
-
"Weight": weight
|
28 |
}
|
29 |
|
30 |
df = pd.DataFrame([questionnaire_data]) # Create DataFrame from dictionary
|
@@ -35,12 +33,12 @@ def submit_questionnaire(name, age, location, gender, height, weight):
|
|
35 |
return "Thank you for completing the questionnaire!"
|
36 |
|
37 |
# Function to handle chat
|
38 |
-
def chat(user_input, messages, name, age, location, gender
|
39 |
if user_input:
|
40 |
# Create a user profile string
|
41 |
user_profile_string = (
|
42 |
f"User profile: Name: {name}, Age: {age}, Location: {location}, "
|
43 |
-
f"Gender: {gender}
|
44 |
)
|
45 |
|
46 |
# Prepare messages for the API call, including the profile and the conversation history
|
@@ -85,23 +83,20 @@ with gr.Blocks() as demo:
|
|
85 |
age = gr.Number(label="Age", value=25, minimum=1, maximum=100)
|
86 |
location = gr.Textbox(label="Location")
|
87 |
gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
|
88 |
-
height = gr.Number(label="Height (cm)", value=170, minimum=50, maximum=250)
|
89 |
-
weight = gr.Number(label="Weight (kg)", value=70, minimum=20, maximum=200)
|
90 |
-
|
91 |
-
with gr.Column():
|
92 |
submit_btn = gr.Button("Submit Questionnaire")
|
93 |
reset_btn = gr.Button("Reset Chat")
|
94 |
|
95 |
# Chat functionality
|
96 |
-
chatbox = gr.Chatbot()
|
97 |
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
98 |
|
|
|
|
|
|
|
99 |
# Connect the buttons to their respective functions
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
reset_btn.click(reset_chat, outputs=[chatbox, "title"])
|
104 |
-
user_input.submit(chat, inputs=[user_input, chatbox, name, age, location, gender, height, weight], outputs=[chatbox, user_input])
|
105 |
|
106 |
# Run the app
|
107 |
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 provides valuable fashion advice, asks relevant questions, and keeps the conversation focused on the user's style and preferences."
|
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, location):
|
20 |
+
# Store questionnaire responses in a DataFrame
|
21 |
questionnaire_data = {
|
22 |
"Name": name,
|
23 |
"Age": age,
|
|
|
24 |
"Gender": gender,
|
25 |
+
"Location": location
|
|
|
26 |
}
|
27 |
|
28 |
df = pd.DataFrame([questionnaire_data]) # Create DataFrame from dictionary
|
|
|
33 |
return "Thank you for completing the questionnaire!"
|
34 |
|
35 |
# Function to handle chat
|
36 |
+
def chat(user_input, messages, name, age, location, gender):
|
37 |
if user_input:
|
38 |
# Create a user profile string
|
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
|
|
|
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 |
+
submit_btn.click(submit_questionnaire, inputs=[name, age, location, gender], outputs=output_message)
|
98 |
+
reset_btn.click(reset_chat, outputs=[chatbox, output_message])
|
99 |
+
user_input.submit(chat, inputs=[user_input, chatbox, name, age, location, gender], outputs=[chatbox, user_input])
|
|
|
|
|
100 |
|
101 |
# Run the app
|
102 |
demo.launch()
|