Spaces:
Build error
Build error
Update app.py
Browse files
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
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def chat_respond(message, history):
|
| 13 |
-
# Format
|
| 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
|
| 20 |
-
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
response = full_text.split("Assistant:")[-1].strip()
|
| 25 |
return response
|
| 26 |
|
| 27 |
-
#
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("# 🐨 Raller Magnium AI")
|
| 30 |
-
gr.Markdown("
|
| 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
|