Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
8 |
|
9 |
initial_message = "Hello! I'm the Apex Customs car configuration assistant. Welcome to Apex Customs, where we specialize in modifying and customizing some of the most popular sports cars and performance vehicles on the market. Our team of experts can help you take your ride to the next level with a wide range of customization options.\nBased on your interest in high-performance vehicles, I'd like to suggest some popular car models that we work with. If you're looking for a sleek and powerful sports car, the Toyota Supra or Nissan GT-R might be a great fit for you. For those who prefer a more classic rally car, the Mitsubishi Lancer Evolution or Subaru WRX STI might be more your style. And if you're a fan of the Honda Civic Type R, we've got you covered there too.\nWhen it comes to customization options, we offer everything from exterior modifications like body kits and spoilers to interior upgrades like seats and steering wheels. We can also help you enhance your car's performance with engine tuning, exhaust systems, and suspension upgrades. And if you're looking to upgrade your audio and entertainment system, we've got you covered there too.\nAs for paint colors, we offer a wide range of options to choose from. Some popular choices include matte black, Nardo gray, midnight purple, riviera blue, and fluorescent green.\nLet us know which car model you're interested in, and we can provide more detailed information about the customization options available for that specific vehicle. Thanks for considering Apex Customs for your next car modification project!\nHow can I help you today?"
|
10 |
|
11 |
-
|
12 |
def respond(
|
13 |
message,
|
14 |
history: list[tuple[str, str]],
|
@@ -16,16 +15,32 @@ def respond(
|
|
16 |
max_tokens,
|
17 |
temperature,
|
18 |
top_p,
|
|
|
19 |
):
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
29 |
|
30 |
response = ""
|
31 |
|
@@ -39,17 +54,22 @@ def respond(
|
|
39 |
token = message.choices[0].delta.content
|
40 |
|
41 |
response += token
|
42 |
-
yield response
|
|
|
|
|
|
|
43 |
|
44 |
"""
|
45 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
46 |
"""
|
47 |
|
|
|
|
|
48 |
demo = gr.ChatInterface(
|
49 |
respond,
|
50 |
chatbot=gr.Chatbot(value=[[None, initial_message]]),
|
51 |
additional_inputs=[
|
52 |
-
gr.Textbox(value=
|
53 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
54 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
55 |
gr.Slider(
|
|
|
8 |
|
9 |
initial_message = "Hello! I'm the Apex Customs car configuration assistant. Welcome to Apex Customs, where we specialize in modifying and customizing some of the most popular sports cars and performance vehicles on the market. Our team of experts can help you take your ride to the next level with a wide range of customization options.\nBased on your interest in high-performance vehicles, I'd like to suggest some popular car models that we work with. If you're looking for a sleek and powerful sports car, the Toyota Supra or Nissan GT-R might be a great fit for you. For those who prefer a more classic rally car, the Mitsubishi Lancer Evolution or Subaru WRX STI might be more your style. And if you're a fan of the Honda Civic Type R, we've got you covered there too.\nWhen it comes to customization options, we offer everything from exterior modifications like body kits and spoilers to interior upgrades like seats and steering wheels. We can also help you enhance your car's performance with engine tuning, exhaust systems, and suspension upgrades. And if you're looking to upgrade your audio and entertainment system, we've got you covered there too.\nAs for paint colors, we offer a wide range of options to choose from. Some popular choices include matte black, Nardo gray, midnight purple, riviera blue, and fluorescent green.\nLet us know which car model you're interested in, and we can provide more detailed information about the customization options available for that specific vehicle. Thanks for considering Apex Customs for your next car modification project!\nHow can I help you today?"
|
10 |
|
|
|
11 |
def respond(
|
12 |
message,
|
13 |
history: list[tuple[str, str]],
|
|
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
18 |
+
max_context_length=4096, # Set the maximum context length
|
19 |
):
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
22 |
+
# Truncate the history to fit within the maximum context length
|
23 |
+
truncated_history = []
|
24 |
+
tokens_so_far = 0
|
25 |
+
for user_input, bot_response in reversed(history):
|
26 |
+
if user_input:
|
27 |
+
tokens_so_far += len(client.tokenizer.encode(user_input))
|
28 |
+
if bot_response:
|
29 |
+
tokens_so_far += len(client.tokenizer.encode(bot_response))
|
30 |
+
|
31 |
+
if tokens_so_far < max_context_length:
|
32 |
+
truncated_history.insert(0, (user_input, bot_response))
|
33 |
+
else:
|
34 |
+
break
|
35 |
+
|
36 |
+
for user_input, bot_response in truncated_history:
|
37 |
+
if user_input:
|
38 |
+
messages.append({"role": "user", "content": user_input})
|
39 |
+
if bot_response:
|
40 |
+
messages.append({"role": "assistant", "content": bot_response})
|
41 |
|
42 |
+
if message:
|
43 |
+
messages.append({"role": "user", "content": message})
|
44 |
|
45 |
response = ""
|
46 |
|
|
|
54 |
token = message.choices[0].delta.content
|
55 |
|
56 |
response += token
|
57 |
+
yield response, truncated_history
|
58 |
+
|
59 |
+
if response:
|
60 |
+
truncated_history.append((message, response))
|
61 |
|
62 |
"""
|
63 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
64 |
"""
|
65 |
|
66 |
+
system_message = "You are a helpful car configuration assistant, specifically you are the assistant for Apex Customs (https://www.apexcustoms.com/). Given the user's input, provide suggestions for car models, colors, and customization options. Be conversational in your responses. You should remember the user's car model and tailor your answers accordingly, referring to the specific car model mentioned by the user. You limit yourself to answering the given question and maybe propose a suggestion but not write the next question of the user."
|
67 |
+
|
68 |
demo = gr.ChatInterface(
|
69 |
respond,
|
70 |
chatbot=gr.Chatbot(value=[[None, initial_message]]),
|
71 |
additional_inputs=[
|
72 |
+
gr.Textbox(value=system_message, label="System message"),
|
73 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
74 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
75 |
gr.Slider(
|