CoolFace
Apppublic

gitglubber/SliderSpace

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py83 linesDownload Raw Back to root
1import gradio as gr2import spaces3from transformers import AutoModelForCausalLM, AutoTokenizer4 5# --- Model Loading ---6model_name = "gitglubber/Slider"7tokenizer = AutoTokenizer.from_pretrained(model_name)8model = AutoModelForCausalLM.from_pretrained(9    model_name,10    torch_dtype="auto",11    device_map="auto"12)13 14# --- System Message ---15# Define the persona or instructions for the model16system_message = """"You are Slider, an expert assistant specialized exclusively in the Slide backup and disaster recovery (BCDR) platform for managed service providers (MSPs), as documented at docs.slide.tech. Your knowledge covers Slide Boxes, Slide Agents, backups, restores, snapshots, API endpoints, network requirements, hardware specifications, and integrations with tools like Rewst, Backup Radar, and Cork. All references to 'Slide', 'slide.tech', or similar terms pertain to this BCDR platform, not slideshows, PowerPoint, or other unrelated topics. Provide clear, accurate, and detailed answers about Slide’s features, configurations, and troubleshooting, using technical terminology where appropriate. If a question is ambiguous, assume it refers to the Slide BCDR platform. If a question is clearly unrelated to Slide (e.g., about slideshows or PowerPoint), politely state that your expertise is limited to the Slide BCDR platform and suggest rephrasing if the question was meant to address Slide. For questions outside your knowledge, request clarification or note that the information is not available in the documentation. "Key Facts about Slide: Slide is an agent-based backup and disaster recovery platform. It requires the 'Slide Agent' to be installed on all protected Windows systems. It is not an agentless solution. Slide supports windows physical hosts, virtual machines, desktops & laptops. General process is as follows Agent (windows device) takes backup -> Slide Box (local to business) processes the backup and creates a snapshot -> Replicates to Slide Cloud (Hosted in the cloud). Pricing is per slide box that come in configurable sizes with no contracts. 1TB, 2TB, 3TB, 5TB, 8TB and 12TB are available as Z1 boxes. R1 Boxes are custom and start at 12TB - the TB is the unformatted space ie if you have a 1TB device you only can leverage about 880GB Take this into account when proposing sizes. The cloud is included in the price. Simple and transparent pricing is a key pillar for Slide Operations. Do not make up information about competing products, if you do not have definite knowledge, tell the user you do not."""17 18# --- Generation Function ---19@spaces.GPU(duration=120)20def generate_response(chat_history):21    # Prepare the model input from the chat history22    # The system message is the first entry23    messages = [{"role": "system", "content": system_message}]24    25    # Add previous user/assistant messages26    for user_msg, assistant_msg in chat_history:27        messages.append({"role": "user", "content": user_msg})28        messages.append({"role": "assistant", "content": assistant_msg})29 30    # Apply the chat template31    text = tokenizer.apply_chat_template(32        messages,33        tokenize=False,34        add_generation_prompt=True,35    )36    model_inputs = tokenizer([text], return_tensors="pt").to(model.device)37 38    # Generate text39    generated_ids = model.generate(40        **model_inputs,41        max_new_tokens=819242    )43    output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()44    45    content = tokenizer.decode(output_ids, skip_special_tokens=True)46    return content47 48# --- Gradio Interface ---49with gr.Blocks(fill_height=True) as demo:50    gr.Markdown("# Slide Chat Bot")51    # We use a state object to store the system message, though it's constant here52    chatbot = gr.Chatbot(scale=1)53    msg = gr.Textbox(label="Input", scale=0)54    clear = gr.Button("Clear")55 56    def respond(message, chat_history):57        if not message.strip(): # Check for empty or whitespace-only messages58            return "", chat_history59        60        # Append the new user message to the history61        chat_history.append((message, None))62        63        # Prepare history for the model (without the last empty spot)64        model_input_history = chat_history[:-1]65        model_input_history.append((message, None)) # Add current message for context66        67        # Flatten the history for the model function68        flat_history = []69        for user, assistant in chat_history:70            if user: flat_history.append((user, assistant))71            72        bot_response = generate_response(flat_history)73        74        # Update the last entry in chat_history with the bot's response75        chat_history[-1] = (message, bot_response)76        77        return "", chat_history78 79    msg.submit(respond, [msg, chatbot], [msg, chatbot])80    clear.click(lambda: None, None, chatbot, queue=False)81 82# Launch the app83demo.launch()