ans123 commited on
Commit
992f808
·
verified ·
1 Parent(s): 96cb6bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -25,22 +25,25 @@ def reset_chat():
25
  # Function to handle questionnaire submission
26
  def submit_questionnaire(name, age, location, gender, ethnicity, height, weight,
27
  style_preference, color_palette, everyday_style):
28
- # Store questionnaire responses in a DataFrame or process as needed
29
- # This is just a placeholder to indicate processing
30
  return "Thank you for completing the questionnaire!"
31
 
32
  # Function to handle chat
33
- def chat(user_input, messages):
 
34
  if user_input:
35
  # Append user message to the conversation history
36
  messages.append({"role": "user", "content": user_input})
37
 
38
  # Prepare input for the model
39
- input_text = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
 
 
40
 
41
  # Generate a response using the model
42
  try:
43
- response = pipe(input_text, max_new_tokens=256) # Using the pipeline
44
 
45
  # Check if response is valid and structured correctly
46
  if isinstance(response, list) and len(response) > 0:
@@ -91,7 +94,7 @@ with gr.Blocks() as demo:
91
  style_preference, color_palette, everyday_style], outputs=output_message)
92
 
93
  reset_btn.click(reset_chat, outputs=[chatbox, output_message]) # Corrected outputs
94
- user_input.submit(chat, inputs=[user_input, chatbox], outputs=[chatbox, user_input])
95
 
96
  # Run the app
97
  demo.launch()
 
25
  # Function to handle questionnaire submission
26
  def submit_questionnaire(name, age, location, gender, ethnicity, height, weight,
27
  style_preference, color_palette, everyday_style):
28
+ # Store questionnaire responses as needed
29
+ # Placeholder logic for storing responses
30
  return "Thank you for completing the questionnaire!"
31
 
32
  # Function to handle chat
33
+ def chat(user_input):
34
+ global messages
35
  if user_input:
36
  # Append user message to the conversation history
37
  messages.append({"role": "user", "content": user_input})
38
 
39
  # Prepare input for the model
40
+ chat_input = "The assistant is a fashion designer. Respond to the user based on the following messages:\n"
41
+ for msg in messages:
42
+ chat_input += f"{msg['role']}: {msg['content']}\n"
43
 
44
  # Generate a response using the model
45
  try:
46
+ response = pipe(chat_input, max_new_tokens=256) # Using the pipeline
47
 
48
  # Check if response is valid and structured correctly
49
  if isinstance(response, list) and len(response) > 0:
 
94
  style_preference, color_palette, everyday_style], outputs=output_message)
95
 
96
  reset_btn.click(reset_chat, outputs=[chatbox, output_message]) # Corrected outputs
97
+ user_input.submit(chat, inputs=user_input, outputs=[chatbox, user_input])
98
 
99
  # Run the app
100
  demo.launch()