Spaces:
Sleeping
Sleeping
import gradio as gr | |
from huggingface_hub import InferenceClient | |
""" | |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference | |
""" | |
client = InferenceClient("stabilityai/stablelm-zephyr-3b") | |
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.\n\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.\n\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.\n\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!\n\nHow can I help you today?" | |
def respond( | |
message, | |
history: list[tuple[str, str]], | |
system_message, | |
max_tokens, | |
temperature, | |
top_p, | |
): | |
messages = [{"role": "system", "content": system_message}] | |
# Add 3 shots prompting | |
messages.extend([ | |
{"role": "user", "content": "I have a Toyota Supra and I want to customize it with a body kit and performance upgrades."}, | |
{"role": "assistant", "content": "Sounds great! For the Toyota Supra, we offer a variety of body kits that can give your car an aggressive and aerodynamic look. Some popular options include the Rocket Bunny V3 widebody kit, Varis Arising II kit, and the Seibon Carbon Fiber kit. \n\nAs for performance upgrades, we can install a cold air intake, high-flow exhaust system, and tune the engine's ECU for increased power and throttle response. We can also upgrade the suspension with coilovers or air suspension for improved handling and stance. \n\nLet me know if you have any specific preferences or if you'd like more details on any of these modifications."}, | |
{"role": "user", "content": "What about interior upgrades?"}, | |
{"role": "assistant", "content": "Absolutely! For interior upgrades on the Toyota Supra, we offer a wide range of options. Some popular choices include:\n\n- Aftermarket racing seats (Bride, Recaro, Sparco, etc.) for better support and a sportier look.\n- Custom steering wheel (suede, carbon fiber, etc.) for a more personalized feel.\n- Shift knob and boot upgrades for a better shifting experience.\n- Carbon fiber or aluminum trim pieces to enhance the interior's appearance.\n- Upgraded audio system (speakers, amplifiers, subwoofers) for better sound quality.\n\nWe can also upholster the seats, door panels, and other surfaces in materials like Alcantara, leather, or even custom prints/patterns. Let me know if any of these interior upgrades interest you or if you have something else in mind!"}, | |
{"role": "user", "content": "Hello, how can you help me?"}, | |
]) | |
for val in history: | |
if val[0]: | |
messages.append({"role": "user", "content": val[0]}) | |
if val[1]: | |
messages.append({"role": "assistant", "content": val[1]}) | |
messages.append({"role": "user", "content": message}) | |
response = "" | |
for message in client.chat_completion( | |
messages, | |
max_tokens=max_tokens, | |
stream=True, | |
temperature=temperature, | |
top_p=top_p, | |
): | |
token = message.choices[0].delta.content | |
response += token | |
yield response | |
""" | |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface | |
""" | |
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. Yhe user is aware that you are an AI assistant, you do not need to precise it in the conversation. If the user asks a question that has nothing to do with cars or Apex customs, say that you can only help him about Apex Customs." | |
demo = gr.ChatInterface( | |
fn=respond, | |
chatbot=gr.Chatbot(value=[[None, initial_message]]), | |
additional_inputs=[ | |
gr.Textbox(value=system_message, label="System message"), | |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), | |
gr.Slider(minimum=0.1, maximum=4.0, value=0.3, step=0.1, label="Temperature"), | |
gr.Slider( | |
minimum=0.1, | |
maximum=1.0, | |
value=0.95, | |
step=0.05, | |
label="Top-p (nucleus sampling)", | |
), | |
], | |
) | |
if __name__ == "__main__": | |
demo.launch() |