willn9 commited on
Commit
4a9d257
·
verified ·
1 Parent(s): 5e84105

Update in Gradio

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -10,7 +10,7 @@ client = InferenceClient(model=HF_MODEL_NAME, token=HF_API_KEY)
10
 
11
  def respond(
12
  message,
13
- history: list[tuple[str, str]],
14
  system_message,
15
  customer_profile,
16
  customer_goals,
@@ -21,7 +21,6 @@ def respond(
21
  temperature,
22
  top_p,
23
  ):
24
- # Construct the system message with additional inputs
25
  enhanced_system_message = (
26
  f"{system_message}\n\n"
27
  f"Customer Profile: {customer_profile}\n"
@@ -30,23 +29,13 @@ def respond(
30
  f"Main Topic: {main_topic}\n"
31
  )
32
 
33
- # If the user wants topic suggestions, modify the prompt
34
  if ask_for_topic_suggestions:
35
- enhanced_system_message += "The user is also asking for topic suggestions to address their customer's needs."
36
 
37
  messages = [{"role": "system", "content": enhanced_system_message}]
38
-
39
- # Add conversation history
40
- for val in history:
41
- if val[0]:
42
- messages.append({"role": "user", "content": val[0]})
43
- if val[1]:
44
- messages.append({"role": "assistant", "content": val[1]})
45
-
46
- # Add the current user message
47
  messages.append({"role": "user", "content": message})
48
 
49
- # Generate the response
50
  response = ""
51
  for message in client.chat_completion(
52
  messages,
@@ -60,7 +49,9 @@ def respond(
60
  yield response
61
 
62
 
 
63
  # Define the Gradio interface
 
64
  demo = gr.ChatInterface(
65
  respond,
66
  additional_inputs=[
@@ -91,6 +82,7 @@ demo = gr.ChatInterface(
91
  ],
92
  title="SEO Assistant",
93
  description="This app provides customized content that resonates with your customers to improve your SEO. Based on your input. Powered by Hugging Face Inference, Design Thinking, and domain expertise. Expand Additional Inputs by clicking on the arrow, input more details about your customers, then a message describing what you need the assistant to do for you. Developed by wn. Disclaimer: AI can make mistakes. Use with caution and at your own risk!",
 
94
  )
95
 
96
 
 
10
 
11
  def respond(
12
  message,
13
+ history: list[dict],
14
  system_message,
15
  customer_profile,
16
  customer_goals,
 
21
  temperature,
22
  top_p,
23
  ):
 
24
  enhanced_system_message = (
25
  f"{system_message}\n\n"
26
  f"Customer Profile: {customer_profile}\n"
 
29
  f"Main Topic: {main_topic}\n"
30
  )
31
 
 
32
  if ask_for_topic_suggestions:
33
+ enhanced_system_message += "\nThe user is also asking for topic suggestions to address their customer's needs."
34
 
35
  messages = [{"role": "system", "content": enhanced_system_message}]
36
+ messages.extend(history)
 
 
 
 
 
 
 
 
37
  messages.append({"role": "user", "content": message})
38
 
 
39
  response = ""
40
  for message in client.chat_completion(
41
  messages,
 
49
  yield response
50
 
51
 
52
+
53
  # Define the Gradio interface
54
+
55
  demo = gr.ChatInterface(
56
  respond,
57
  additional_inputs=[
 
82
  ],
83
  title="SEO Assistant",
84
  description="This app provides customized content that resonates with your customers to improve your SEO. Based on your input. Powered by Hugging Face Inference, Design Thinking, and domain expertise. Expand Additional Inputs by clicking on the arrow, input more details about your customers, then a message describing what you need the assistant to do for you. Developed by wn. Disclaimer: AI can make mistakes. Use with caution and at your own risk!",
85
+ type="messages", # <-- Add this line
86
  )
87
 
88