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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -97
app.py CHANGED
@@ -1,100 +1,4 @@
1
  import gradio as gr
2
- import torch
3
- from transformers import pipeline
4
 
5
  # Load the Qwen2.5-72B-Instruct model
6
- pipe = pipeline(
7
- "text-generation",
8
- model="HuggingFaceH4/Qwen2.5-72B-Instruct",
9
- model_kwargs={"torch_dtype": torch.bfloat16},
10
- device_map="auto",
11
- )
12
-
13
- # Initial messages list for chat history
14
- messages = [
15
- {"role": "system", "content": "You are an experienced Fashion designer who starts conversation with proper greeting, "
16
- "giving valuable and catchy fashion advice and suggestions, stays to the point and precise."}
17
- ]
18
-
19
- # Function to reset the chat
20
- def reset_chat():
21
- global messages
22
- messages = [] # Reset the message history
23
- return [], "New Chat"
24
-
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:
50
- response_content = response[0]['generated_text'].strip() # Accessing generated text
51
- else:
52
- response_content = "Sorry, I couldn't generate a response."
53
-
54
- except Exception as e:
55
- response_content = f"Error: {str(e)}"
56
-
57
- # Store assistant response in the chat history
58
- messages.append({"role": "assistant", "content": response_content})
59
-
60
- return messages, response_content
61
- return messages, ""
62
-
63
- # Gradio Interface
64
- with gr.Blocks() as demo:
65
- gr.Markdown("## Fashion Assistant Chatbot")
66
-
67
- # Sidebar for user inputs
68
- with gr.Row():
69
- with gr.Column():
70
- name = gr.Textbox(label="Name")
71
- age = gr.Number(label="Age", value=25, minimum=1, maximum=100)
72
- location = gr.Textbox(label="Location")
73
- gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
74
- ethnicity = gr.Radio(label="Ethnicity", choices=["Asian", "Black", "Hispanic", "White", "Other"])
75
- height = gr.Number(label="Height (cm)", value=170, minimum=50, maximum=250)
76
- weight = gr.Number(label="Weight (kg)", value=70, minimum=20, maximum=200)
77
-
78
- with gr.Column():
79
- submit_btn = gr.Button("Submit Questionnaire")
80
- reset_btn = gr.Button("Reset Chat")
81
-
82
- # Questionnaire with fashion-related questions
83
- style_preference = gr.Radio(label="Which style do you prefer the most?", choices=["Casual", "Formal", "Streetwear", "Athleisure", "Baggy"])
84
- color_palette = gr.Radio(label="What color palette do you wear often?", choices=["Neutrals", "Bright Colors", "Pastels", "Dark Shades"])
85
- everyday_style = gr.Radio(label="How would you describe your everyday style?", choices=["Relaxed", "Trendy", "Elegant", "Bold"])
86
-
87
- # Chat functionality
88
- chatbox = gr.Chatbot(type='messages')
89
- user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
90
-
91
- # Connect the buttons to their respective functions
92
- output_message = gr.Textbox(label="Output Message")
93
- submit_btn.click(submit_questionnaire, inputs=[name, age, location, gender, ethnicity, height, weight,
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()
 
1
  import gradio as gr
 
 
2
 
3
  # Load the Qwen2.5-72B-Instruct model
4
+ model = gr.load("models/Qwen/Qwen2.5-72B-Instruct")