Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
from llama_cpp import Llama
|
| 5 |
+
|
| 6 |
+
# Model config
|
| 7 |
+
REPO_ID = "darkc0de/XORTRON-XPRT3-FAST"
|
| 8 |
+
FILENAME = "XORTRON-XPRT3-Q1_S.gguf" # Quantized model size ~899MB
|
| 9 |
+
|
| 10 |
+
print("Downloading model from HF Hub...")
|
| 11 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 12 |
+
|
| 13 |
+
print("Loading GGUF model on CPU...")
|
| 14 |
+
llm = Llama(
|
| 15 |
+
model_path=model_path,
|
| 16 |
+
n_threads=2, # Free CPU tier me 2 threads optimized rehte hain
|
| 17 |
+
n_ctx=2048,
|
| 18 |
+
verbose=False
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
def generate_response(message, history, max_tokens, temperature):
|
| 22 |
+
prompt = f"User: {message}\nAssistant:"
|
| 23 |
+
|
| 24 |
+
output = llm(
|
| 25 |
+
prompt,
|
| 26 |
+
max_tokens=int(max_tokens),
|
| 27 |
+
temperature=float(temperature),
|
| 28 |
+
stop=["User:", "\n\n"]
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
return output["choices"][0]["text"].strip()
|
| 32 |
+
|
| 33 |
+
demo = gr.ChatInterface(
|
| 34 |
+
fn=generate_response,
|
| 35 |
+
additional_inputs=[
|
| 36 |
+
gr.Slider(minimum=16, maximum=1024, value=256, step=16, label="Max Tokens"),
|
| 37 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
|
| 38 |
+
],
|
| 39 |
+
title="XORTRON-XPRT3 (Docker CPU)",
|
| 40 |
+
description="Running GGUF Quantized Model via Docker on HF Free CPU."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
# HF Docker environment ke liye server_name="0.0.0.0" aur port=7860 zaroori hai
|
| 45 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|