Jodaro commited on
Commit
cbf8005
·
verified ·
1 Parent(s): dd85444

Create app.py with ctransformers

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ctransformers import AutoModelForCausalLM
3
+
4
+ MODEL_REPO = "bartowski/Hermes-3-Llama-3.1-8B-GGUF"
5
+ MODEL_FILE = "Hermes-3-Llama-3.1-8B-Q4_K_M.gguf"
6
+
7
+ print("Loading model...")
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ MODEL_REPO,
10
+ model_file=MODEL_FILE,
11
+ hf_model=MODEL_REPO,
12
+ gpu_layers=0,
13
+ context_length=4096,
14
+ )
15
+
16
+ def respond(message, history):
17
+ prompt = ""
18
+ for user_msg, bot_msg in history:
19
+ prompt += f"<|im_start|>user\n{user_msg}\n<|im_end|>\n"
20
+ prompt += f"<|im_start|>assistant\n{bot_msg}\n<|im_end|>\n"
21
+ prompt += f"<|im_start|>user\n{message}\n<|im_end|>\n<|im_start|>assistant\n"
22
+ output = model(prompt, max_new_tokens=512, temperature=0.7, top_p=0.9)
23
+ return output
24
+
25
+ iface = gr.ChatInterface(respond)
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()