AlphaNightLight commited on
Commit
f08d339
·
verified ·
1 Parent(s): ff8d971

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -13,9 +13,29 @@ LOCAL_FLAGS = "flags.json" # You must save locally before push to hf
13
 
14
  print("Loading model...")
15
 
 
 
 
 
 
 
 
 
 
16
  ### The Chat Model
17
  def chat_model(message, history):
18
- return message[::-1] # dummy: reverse text
 
 
 
 
 
 
 
 
 
 
 
19
 
20
 
21
 
@@ -111,7 +131,7 @@ with gr.Blocks() as app:
111
 
112
  good_btn.click(
113
  lambda history, reason: save_flag_to_dataset(history, reason),
114
- inputs=[chat_box.chatbot, "GOOD"],
115
  outputs=feedback_status
116
  )
117
 
 
13
 
14
  print("Loading model...")
15
 
16
+ llm = Llama.from_pretrained(
17
+ repo_id=MODEL_REPO,
18
+ filename=MODEL_FILE,
19
+ n_threads=2,
20
+ n_batch=128,
21
+ n_ctx=2048,
22
+ temperature=0.7
23
+ )
24
+
25
  ### The Chat Model
26
  def chat_model(message, history):
27
+
28
+ # Retrieve the context
29
+ prompt = ""
30
+ for item in history:
31
+ role = item["role"]
32
+ text = item["content"][0]["text"]
33
+ prompt += f"<|{role}|>{text}\n"
34
+ prompt += f"<|user|>{message}\n<|assistant|>"
35
+
36
+ # Invoke the model
37
+ output = llm(prompt, max_tokens=350)
38
+ return output["choices"][0]["text"].strip()
39
 
40
 
41
 
 
131
 
132
  good_btn.click(
133
  lambda history, reason: save_flag_to_dataset(history, reason),
134
+ inputs=[chat_box.chatbot, gr.Markdown("GOOD")],
135
  outputs=feedback_status
136
  )
137