Mhammad-Raller commited on
Commit
0d234e9
·
verified ·
1 Parent(s): 366ac6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -4,32 +4,37 @@
4
  # it under the terms of the GNU General Public License v3.
5
 
6
  import gradio as gr
7
- from transformers import pipeline
 
8
 
9
- # Load the SmolLM 1.7B Instruct model cleanly
10
- generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct")
 
 
 
 
 
 
11
 
12
  def chat_respond(message, history):
13
- # Format basic text history for the AI engine
14
  prompt = ""
15
  for user_msg, ai_msg in history:
16
  prompt += f"User: {user_msg}\nAssistant: {ai_msg}\n"
17
  prompt += f"User: {message}\nAssistant:"
18
 
19
- # Generate response string tokens
20
- results = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
21
 
22
- # Extract only the text that follows the final Assistant label
23
- full_text = results['generated_text']
24
- response = full_text.split("Assistant:")[-1].strip()
25
  return response
26
 
27
- # Create the clean, error-free chatbot block layout
28
  with gr.Blocks() as demo:
29
- gr.Markdown("# 🐨 Raller Magnium AI")
30
- gr.Markdown("Welcome to our small AI system, hope you like it. Powered by raller.pro.")
31
 
32
- # The universal ChatInterface engine built into Gradio
33
  gr.ChatInterface(fn=chat_respond)
34
 
35
  # Launch with the soft UI theme cleanly applied
 
4
  # it under the terms of the GNU General Public License v3.
5
 
6
  import gradio as gr
7
+ from huggingface_hub import hf_hub_download
8
+ from llama_cpp import Llama
9
 
10
+ # 1. Download the ultra-fast CPU version of SmolLM 1.7B (GGUF format)
11
+ model_path = hf_hub_download(
12
+ repo_id="second-state/SmolLM-1.7B-Instruct-GGUF",
13
+ filename="SmolLM-1.7B-Instruct-Q4_K_M.gguf"
14
+ )
15
+
16
+ # 2. Boot up the high-speed CPU inference engine
17
+ llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2)
18
 
19
  def chat_respond(message, history):
20
+ # Format a fast prompt string for the engine
21
  prompt = ""
22
  for user_msg, ai_msg in history:
23
  prompt += f"User: {user_msg}\nAssistant: {ai_msg}\n"
24
  prompt += f"User: {message}\nAssistant:"
25
 
26
+ # Generate tokens instantly using your free CPU cores
27
+ output = llm(prompt, max_tokens=120, temperature=0.7, stop=["User:"])
28
 
29
+ # Clean up and extract the text
30
+ response = output["choices"][0]["text"].strip()
 
31
  return response
32
 
33
+ # Build the layout block
34
  with gr.Blocks() as demo:
35
+ gr.Markdown("# 🐨 Raller Magnium AI (High-Speed Engine)")
36
+ gr.Markdown("Optimized for lightning-fast responses on free cloud hardware. Powered by raller.pro.")
37
 
 
38
  gr.ChatInterface(fn=chat_respond)
39
 
40
  # Launch with the soft UI theme cleanly applied