File size: 7,237 Bytes
31b863d f2c765e 31b863d 97c4502 31b863d f2c765e bd69f09 31b863d f2c765e 31b863d f2c765e 31b863d 5d951f6 31b863d f2c765e 31b863d f2c765e 31b863d 3b371eb 31b863d f2c765e 5d951f6 31b863d f2c765e 97c4502 5d951f6 97c4502 5d951f6 97c4502 5d951f6 3b371eb 5d951f6 3b371eb 5d951f6 3b371eb 97c4502 5d951f6 31b863d 2dcd8c5 3b371eb 97c4502 3b371eb 5d951f6 f2c765e 31b863d 740ea71 31b863d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
import gradio as gr
import pandas as pd
from groq import Groq
# Initialize the Groq client with your API key
client = Groq(api_key="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")
# Define the system message for the model
system_message = {
"role": "system",
"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."
}
# Function to reset the chat
def reset_chat():
return [], "New Chat"
# Function to handle the questionnaire submission
def submit_questionnaire(name, age, location, gender, ethnicity, height, weight,
style_preference, color_palette, everyday_style):
# Store questionnaire responses in a DataFrame
questionnaire_data = {
"Name": name,
"Age": age,
"Location": location,
"Gender": gender,
"Ethnicity": ethnicity,
"Height": height,
"Weight": weight,
"Style Preference": style_preference,
"Color Palette": color_palette,
"Everyday Style": everyday_style
}
df = pd.DataFrame([questionnaire_data]) # Create DataFrame from dictionary
# Append to CSV file
df.to_csv("questionnaire_responses.csv", mode='a', header=not pd.io.common.file_exists("questionnaire_responses.csv"), index=False)
return "Thank you for completing the questionnaire!"
# Function to collect responses to additional fashion-related questions
def collect_questionnaire_responses(style_preference, color_palette, everyday_style):
# Store additional responses in a DataFrame
additional_data = {
"Style Preference": style_preference,
"Color Palette": color_palette,
"Everyday Style": everyday_style
}
df = pd.DataFrame([additional_data]) # Create DataFrame from dictionary
# Append to CSV file
df.to_csv("additional_questionnaire_responses.csv", mode='a', header=not pd.io.common.file_exists("additional_questionnaire_responses.csv"), index=False)
return "Thank you for answering the additional questions!"
# Function to handle chat
def chat(user_input, messages):
if user_input:
# Prepare messages for the API call
messages.append({"role": "user", "content": user_input})
try:
# Generate a response from the Groq API
completion = client.chat.completions.create(
model="llama3-8b-8192",
messages=messages,
temperature=1,
max_tokens=1024,
top_p=1,
stream=False,
)
# Ensure response is valid
if completion.choices and len(completion.choices) > 0:
response_content = completion.choices[0].message.content
else:
response_content = "Sorry, I couldn't generate a response."
except Exception as e:
response_content = f"Error: {str(e)}"
# Store assistant response in the chat history
messages.append({"role": "assistant", "content": response_content})
return messages, response_content
return messages, ""
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("## FRIDAY")
# Sidebar for user inputs
with gr.Row():
with gr.Column():
name = gr.Textbox(label="Name")
age = gr.Number(label="Age", value=25, minimum=1, maximum=100)
location = gr.Textbox(label="Location")
gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
ethnicity = gr.Radio(label="Ethnicity", choices=["Asian", "Black", "Hispanic", "White", "Other"])
height = gr.Number(label="Height (cm)", value=170, minimum=50, maximum=250)
weight = gr.Number(label="Weight (kg)", value=70, minimum=20, maximum=200)
with gr.Column():
submit_btn = gr.Button("Submit User Inputs")
reset_btn = gr.Button("Reset Chat")
# Questionnaire with fashion-related questions
style_preference = gr.Radio(label="Which style do you prefer the most?", choices=["Casual", "Formal", "Streetwear", "Athleisure", "Baggy"])
color_palette = gr.Radio(label="What color palette do you wear often?", choices=["Neutrals", "Bright Colors", "Pastels", "Dark Shades"])
everyday_style = gr.Radio(label="How would you describe your everyday style?", choices=["Relaxed", "Trendy", "Elegant", "Bold"])
# Additional fashion-related questions
fashion_questions = [
("What do you prioritize when choosing an outfit?", ["Comfort", "Style", "Affordability", "Brand"]),
("How often do you experiment with new trends?", ["Always", "Sometimes", "Rarely", "Never"]),
("What kind of accessories do you usually wear?", ["Watches", "Rings", "Necklaces", "Bracelets", "Earrings"]),
("Do you follow fashion trends?", ["Always", "Sometimes", "Never"]),
("How satisfied are you with your wardrobe?", ["Yes", "No"]),
("Do you consider your style unique?", ["Yes", "No"]),
("How confident do you feel in your style?", ["Very Confident", "Somewhat Confident", "Not Confident"]),
("Where do you look for fashion inspiration?", ["Social Media", "Fashion Magazines", "Friends", "Other"]),
("Do you have specific attire for special occasions?", ["Yes", "No"]),
("Do you wear gender-neutral clothing?", ["Yes", "No"]),
("What influences your fashion choices the most?", ["Celebrities", "Social Media", "Friends", "Personal Preference"]),
("Do you enjoy shopping for clothes?", ["Yes", "No"]),
("How often do you declutter your wardrobe?", ["Regularly", "Occasionally", "Rarely"]),
("Do you have a favorite fashion brand?", ["Yes", "No"]),
("How do you feel about thrift shopping?", ["Love it", "Neutral", "Dislike it"]),
]
# Create a separate button for the questionnaire
fill_questionnaire_btn = gr.Button("Fill Additional Questionnaire")
# Adding additional questions
additional_responses = []
for question, choices in fashion_questions:
additional_responses.append(gr.Radio(label=question, choices=choices))
# Chat functionality
chatbox = gr.Chatbot(type='messages')
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
# Connect the buttons to their respective functions
submit_btn.click(
submit_questionnaire,
inputs=[name, age, location, gender, ethnicity, height, weight,
style_preference, color_palette, everyday_style],
outputs=gr.Textbox(label="Submission Response")
)
fill_questionnaire_btn.click(
collect_questionnaire_responses,
inputs=[style_preference, color_palette, everyday_style],
outputs=gr.Textbox(label="Additional Questions Response")
)
# Corrected reset button output
reset_btn.click(reset_chat, outputs=[chatbox, "title"])
user_input.submit(chat, inputs=[user_input, chatbox], outputs=[chatbox, user_input])
# Run the app
demo.launch()
|