Mikecode123 commited on
Commit
ac8b75a
·
verified ·
1 Parent(s): 3150e9f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from llama_cpp import Llama
3
+ from huggingface_hub import hf_hub_download
4
+
5
+ # =========================
6
+ # LOAD MODEL FROM HF REPO
7
+ # =========================
8
+ model_path = hf_hub_download(
9
+ repo_id="Mikecode123/ALX",
10
+ filename="qwen2-1_5b-instruct-q4_0.gguf"
11
+ )
12
+
13
+ llm = Llama(
14
+ model_path=model_path,
15
+ n_ctx=1024,
16
+ n_threads=2
17
+ )
18
+
19
+ # =========================
20
+ # CHAT FUNCTION
21
+ # =========================
22
+ def chat(prompt, history):
23
+ messages = []
24
+
25
+ # convert gradio history to chat format
26
+ for user_msg, bot_msg in history:
27
+ messages.append({"role": "user", "content": user_msg})
28
+ messages.append({"role": "assistant", "content": bot_msg})
29
+
30
+ messages.append({"role": "user", "content": prompt})
31
+
32
+ output = llm.create_chat_completion(
33
+ messages=messages,
34
+ max_tokens=500,
35
+ temperature=0.7
36
+ )
37
+
38
+ response = output["choices"][0]["message"]["content"]
39
+
40
+ history.append((prompt, response))
41
+ return "", history
42
+
43
+ # =========================
44
+ # GRADIO UI
45
+ # =========================
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")
48
+
49
+ chatbot = gr.Chatbot()
50
+ msg = gr.Textbox(label="Ask your AI")
51
+ clear = gr.Button("Clear")
52
+
53
+ msg.submit(chat, [msg, chatbot], [msg, chatbot])
54
+ clear.click(lambda: None, None, chatbot)
55
+
56
+ # =========================
57
+ # LAUNCH
58
+ # =========================
59
+ demo.launch()