gitglubber commited on
Commit
76c652f
·
verified ·
1 Parent(s): 7d832dd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ # --- Model Loading ---
6
+ model_name = "gitglubber/Slider"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = 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 model
16
+ system_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)
20
+ def generate_response(chat_history):
21
+ # Prepare the model input from the chat history
22
+ # The system message is the first entry
23
+ messages = [{"role": "system", "content": system_message}]
24
+
25
+ # Add previous user/assistant messages
26
+ 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 template
31
+ 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 text
39
+ generated_ids = model.generate(
40
+ **model_inputs,
41
+ max_new_tokens=1024
42
+ )
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 content
47
+
48
+ # --- Gradio Interface ---
49
+ with gr.Blocks() as demo:
50
+ gr.Markdown("# Qwen Chatbot")
51
+ # We use a state object to store the system message, though it's constant here
52
+ chatbot = gr.Chatbot()
53
+ msg = gr.Textbox(label="Input")
54
+ clear = gr.Button("Clear")
55
+
56
+ def respond(message, chat_history):
57
+ if not message.strip(): # Check for empty or whitespace-only messages
58
+ return "", chat_history
59
+
60
+ # Append the new user message to the history
61
+ 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 context
66
+
67
+ # Flatten the history for the model function
68
+ 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 response
75
+ chat_history[-1] = (message, bot_response)
76
+
77
+ return "", chat_history
78
+
79
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
80
+ clear.click(lambda: None, None, chatbot, queue=False)
81
+
82
+ # Launch the app
83
+ demo.launch()