Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,26 +9,27 @@ from huggingface_hub import hf_hub_download
|
|
| 9 |
model_path = hf_hub_download(
|
| 10 |
repo_id="Mikecode123/ALX",
|
| 11 |
filename="qwen2-1_5b-instruct-q4_0.gguf",
|
| 12 |
-
token=os.getenv("HF_TOKEN")
|
| 13 |
)
|
| 14 |
|
| 15 |
llm = Llama(
|
| 16 |
model_path=model_path,
|
| 17 |
-
n_ctx=512,
|
| 18 |
-
n_threads=1
|
| 19 |
)
|
| 20 |
|
| 21 |
# =========================
|
| 22 |
-
# CHAT FUNCTION
|
| 23 |
# =========================
|
| 24 |
-
def chat(
|
|
|
|
| 25 |
messages = []
|
| 26 |
|
| 27 |
-
for
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
messages.append({"role": "user", "content":
|
| 32 |
|
| 33 |
output = llm.create_chat_completion(
|
| 34 |
messages=messages,
|
|
@@ -37,7 +38,9 @@ def chat(prompt, history):
|
|
| 37 |
)
|
| 38 |
|
| 39 |
response = output["choices"][0]["message"]["content"]
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
return "", history
|
| 43 |
|
|
@@ -47,14 +50,20 @@ def chat(prompt, history):
|
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")
|
| 49 |
|
| 50 |
-
chatbot = gr.Chatbot()
|
| 51 |
msg = gr.Textbox(label="Ask your AI")
|
| 52 |
clear = gr.Button("Clear")
|
| 53 |
|
| 54 |
msg.submit(chat, [msg, chatbot], [msg, chatbot])
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
# =========================
|
| 58 |
-
# LAUNCH
|
| 59 |
# =========================
|
| 60 |
-
demo.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
model_path = hf_hub_download(
|
| 10 |
repo_id="Mikecode123/ALX",
|
| 11 |
filename="qwen2-1_5b-instruct-q4_0.gguf",
|
| 12 |
+
token=os.getenv("HF_TOKEN")
|
| 13 |
)
|
| 14 |
|
| 15 |
llm = Llama(
|
| 16 |
model_path=model_path,
|
| 17 |
+
n_ctx=512,
|
| 18 |
+
n_threads=1
|
| 19 |
)
|
| 20 |
|
| 21 |
# =========================
|
| 22 |
+
# CHAT FUNCTION (MODERN FORMAT)
|
| 23 |
# =========================
|
| 24 |
+
def chat(message, history):
|
| 25 |
+
# convert Gradio "messages" format safely
|
| 26 |
messages = []
|
| 27 |
|
| 28 |
+
for msg in history:
|
| 29 |
+
if isinstance(msg, dict):
|
| 30 |
+
messages.append(msg)
|
| 31 |
|
| 32 |
+
messages.append({"role": "user", "content": message})
|
| 33 |
|
| 34 |
output = llm.create_chat_completion(
|
| 35 |
messages=messages,
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
response = output["choices"][0]["message"]["content"]
|
| 41 |
+
|
| 42 |
+
history.append({"role": "user", "content": message})
|
| 43 |
+
history.append({"role": "assistant", "content": response})
|
| 44 |
|
| 45 |
return "", history
|
| 46 |
|
|
|
|
| 50 |
with gr.Blocks() as demo:
|
| 51 |
gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")
|
| 52 |
|
| 53 |
+
chatbot = gr.Chatbot(type="messages")
|
| 54 |
msg = gr.Textbox(label="Ask your AI")
|
| 55 |
clear = gr.Button("Clear")
|
| 56 |
|
| 57 |
msg.submit(chat, [msg, chatbot], [msg, chatbot])
|
| 58 |
+
|
| 59 |
+
clear.click(lambda: [], None, chatbot, queue=False)
|
| 60 |
|
| 61 |
# =========================
|
| 62 |
+
# LAUNCH (SPACE SAFE)
|
| 63 |
# =========================
|
| 64 |
+
demo.queue()
|
| 65 |
+
|
| 66 |
+
demo.launch(
|
| 67 |
+
server_name="0.0.0.0",
|
| 68 |
+
server_port=7860
|
| 69 |
+
)
|