sam2ai commited on
Commit
1f946a1
·
1 Parent(s): afcf53f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import copy
4
+ import time
5
+ import llama_cpp
6
+ from llama_cpp import Llama
7
+ from huggingface_hub import hf_hub_download
8
+
9
+
10
+ llm = Llama(
11
+ model_path=hf_hub_download(
12
+ repo_id=os.environ.get("REPO_ID", "sam2ai/open_llama_3b_odia_q4-0_gguf"),
13
+ filename=os.environ.get("MODEL_FILE", "ggml-model-q4_1.gguf"),
14
+ ),
15
+ n_ctx=512
16
+ # n_gpu_layers=50, # change n_gpu_layers if you have more or less VRAM
17
+ )
18
+
19
+ # history = []
20
+
21
+ # system_message = """
22
+ # You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
23
+ # If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
24
+ # """
25
+
26
+
27
+ def generate_text(message):
28
+ # temp = ""
29
+ # input_prompt = f"[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n "
30
+ # for interaction in history:
31
+ # input_prompt = input_prompt + str(interaction[0]) + " [/INST] " + str(interaction[1]) + " </s><s> [INST] "
32
+
33
+ input_prompt = f"### Instruction:\n{message}\n\n### Response:\n"
34
+
35
+ output = llm(
36
+ input_prompt,
37
+ temperature=0.15,
38
+ top_p=0.1,
39
+ top_k=40,
40
+ repeat_penalty=1.1,
41
+ max_tokens=512,
42
+ stop=["</s>"],
43
+ stream=True,
44
+ )
45
+ for out in output:
46
+ stream = copy.deepcopy(out)
47
+ temp += stream["choices"][0]["text"]
48
+ yield temp
49
+
50
+ # history = ["init", input_prompt]
51
+
52
+
53
+ demo = gr.ChatInterface(
54
+ generate_text,
55
+ title="llama-cpp-python on GPU",
56
+ description="Running LLM with https://github.com/abetlen/llama-cpp-python",
57
+ examples=["ତୁମେ କିଏ?"],
58
+ cache_examples=True,
59
+ retry_btn=None,
60
+ undo_btn="Delete Previous",
61
+ clear_btn="Clear",
62
+ )
63
+ demo.queue(concurrency_count=1, max_size=5)
64
+ demo.launch()