fjassim commited on
Commit
dd43894
·
verified ·
1 Parent(s): c2a0859

Update app.py

Browse files

Added comments

Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -1,32 +1,41 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
 
5
  response = ""
6
 
 
7
  def load_weather_info():
8
  with open("chicago_weather.txt", "r", encoding="utf-8") as file:
9
  design_knowledge = file.read()
10
  return design_knowledge
11
 
 
12
  def load_aesthetics_info():
13
  with open("clothing_aesthetics_breakdown.txt", "r", encoding="utf-8") as file:
14
  aesthetics_knowledge = file.read()
15
  return aesthetics_knowledge
16
-
 
17
  def respond(message, history):
18
 
 
19
  weather = load_weather_info()
20
  aesthetics = load_aesthetics_info()
 
21
  messages = [{"role": "system",
22
  "content": f"You are an expert in picking out awesome cute outfits based on the weather in Chicago using this info: {weather} and based on aesthetics styles using this info: {aesthetics}. If the user asks for an outfit, give a top, bottom, and shoe recommendation with details about color, material, and length based on the current weather. Ask them about their preferred style to collect knowledge on what to recommend. Keep the response to 250 words while being friendly and informal!"}]
23
-
 
24
  if history:
25
  messages.extend(history)
26
-
 
27
  messages.append({"role": "user", "content": message})
28
 
29
- # Adjusted temperature to be variable enough to offer a diversity of possible solutions
30
  response = client.chat_completion(
31
  messages,
32
  max_tokens=350,
@@ -34,12 +43,14 @@ def respond(message, history):
34
  stream=True
35
  )
36
 
 
37
  responses = ""
38
  for message in response:
39
  token = message.choices[0].delta.content
40
  responses += token
41
  yield responses
42
 
 
43
  chatbot = gr.ChatInterface(respond)
44
 
45
  chatbot.launch(debug=True)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # the training data to use
5
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
6
+ # the container of the response of the chatbot
7
  response = ""
8
 
9
+ # load climate information on Chicago to instruct chatbot
10
  def load_weather_info():
11
  with open("chicago_weather.txt", "r", encoding="utf-8") as file:
12
  design_knowledge = file.read()
13
  return design_knowledge
14
 
15
+ # load aesthetics info on different styles to instruct chatbot on what styles to recommend and what theyre comprised of
16
  def load_aesthetics_info():
17
  with open("clothing_aesthetics_breakdown.txt", "r", encoding="utf-8") as file:
18
  aesthetics_knowledge = file.read()
19
  return aesthetics_knowledge
20
+
21
+ # function where chatbot, whose role is outfit picker, generates response in a visual stream
22
  def respond(message, history):
23
 
24
+ # load info from txt files
25
  weather = load_weather_info()
26
  aesthetics = load_aesthetics_info()
27
+ # hold messages from chat and assign role to chatbot
28
  messages = [{"role": "system",
29
  "content": f"You are an expert in picking out awesome cute outfits based on the weather in Chicago using this info: {weather} and based on aesthetics styles using this info: {aesthetics}. If the user asks for an outfit, give a top, bottom, and shoe recommendation with details about color, material, and length based on the current weather. Ask them about their preferred style to collect knowledge on what to recommend. Keep the response to 250 words while being friendly and informal!"}]
30
+
31
+ # if there is a history add the message to it
32
  if history:
33
  messages.extend(history)
34
+
35
+ # add the user's message as their content
36
  messages.append({"role": "user", "content": message})
37
 
38
+ # make responses appear as a stream, limit to 350 tokens, and temp 0.6 to be both creative and direct
39
  response = client.chat_completion(
40
  messages,
41
  max_tokens=350,
 
43
  stream=True
44
  )
45
 
46
+ # holds responses of the chatbot
47
  responses = ""
48
  for message in response:
49
  token = message.choices[0].delta.content
50
  responses += token
51
  yield responses
52
 
53
+ # define chatbot
54
  chatbot = gr.ChatInterface(respond)
55
 
56
  chatbot.launch(debug=True)