freddyaboulton HF staff commited on
Commit
4abac18
1 Parent(s): 306a37e
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from llama_cpp import Llama
3
+
4
+ llm = Llama(
5
+ model_path="./qwen2-0_5b-instruct-q5_k_m.gguf",
6
+ verbose=True
7
+ )
8
+
9
+ def predict(message, history):
10
+ messages = [{"role": "system", "content": "You are a helpful assistant."}]
11
+ for user_message, bot_message in history:
12
+ if user_message:
13
+ messages.append({"role": "user", "content": user_message})
14
+ if bot_message:
15
+ messages.append({"role": "assistant", "content": bot_message})
16
+ messages.append({"role": "user", "content": message})
17
+
18
+ response = ""
19
+ for chunk in llm.create_chat_completion(
20
+ stream=True,
21
+ messages=messages,
22
+ ):
23
+ part = chunk["choices"][0]["delta"].get("content", None)
24
+ if part:
25
+ response += part
26
+ yield response
27
+
28
+ demo = gr.ChatInterface(predict)
29
+
30
+ if __name__ == "__main__":
31
+ demo.launch()