Staticaliza commited on
Commit
5510202
1 Parent(s): 0094eb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -11,6 +11,10 @@ KEY = os.environ.get("KEY")
11
 
12
  SPECIAL_SYMBOLS = ["‹", "›"]
13
 
 
 
 
 
14
  API_ENDPOINTS = {
15
  "Falcon": "tiiuae/falcon-180B-chat",
16
  "Llama": "meta-llama/Llama-2-70b-chat-hf"
@@ -23,11 +27,12 @@ for model_name, model_endpoint in API_ENDPOINTS.items():
23
  CHOICES.append(model_name)
24
  CLIENTS[model_name] = InferenceClient(model_endpoint, headers = { "Authorization": f"Bearer {API_TOKEN}" })
25
 
26
- def format(instruction = "", history = [], input = "", preinput = ""):
27
  print(history)
28
  sy_l, sy_r = SPECIAL_SYMBOLS[0], SPECIAL_SYMBOLS[1]
29
  formatted_history = '\n'.join(f"{sy_l}{message}{sy_r}" for message in history)
30
  formatted_input = f"System: {sy_l}{instruction}{sy_r}\n{formatted_history}\n{sy_l}{input}{sy_r}\n{preinput}"
 
31
  return formatted_input
32
 
33
  def predict(instruction, history, input, preinput, access_key, model, temperature, top_p, top_k, rep_p, max_tokens, stop_seqs, seed):
@@ -64,7 +69,7 @@ def predict(instruction, history, input, preinput, access_key, model, temperatur
64
  history = history + [[input, get_result]]
65
 
66
  print(f"---\nUSER: {input}\nBOT: {get_result}\n---")
67
- print(history)
68
  return (get_result, input, history)
69
 
70
  def clear_history():
@@ -81,9 +86,9 @@ with gr.Blocks() as demo:
81
  with gr.Row():
82
  with gr.Column():
83
  history = gr.Chatbot(elem_id = "chatbot")
84
- input = gr.Textbox(label = "Input", lines = 2)
85
- preinput = gr.Textbox(label = "Pre-Input", lines = 1)
86
- instruction = gr.Textbox(label = "Instruction", lines = 4)
87
  access_key = gr.Textbox(label = "Access Key", lines = 1)
88
  run = gr.Button("▶")
89
  clear = gr.Button("🗑️")
 
11
 
12
  SPECIAL_SYMBOLS = ["‹", "›"]
13
 
14
+ DEFAULT_INPUT = f"You: {SPECIAL_SYMBOLS[0]}Hi!{SPECIAL_SYMBOLS[1]}"
15
+ DEFAULT_PREINPUT = f"AI: {SPECIAL_SYMBOLS[0]}"
16
+ DEFAULT_INSTRUCTION = "You are an helpful chatbot. You must respond in this format: \"NAME: ‹MESSAGE›\""
17
+
18
  API_ENDPOINTS = {
19
  "Falcon": "tiiuae/falcon-180B-chat",
20
  "Llama": "meta-llama/Llama-2-70b-chat-hf"
 
27
  CHOICES.append(model_name)
28
  CLIENTS[model_name] = InferenceClient(model_endpoint, headers = { "Authorization": f"Bearer {API_TOKEN}" })
29
 
30
+ def format(instruction = DEFAULT_INSTRUCTION, history = [], input = "", preinput = ""):
31
  print(history)
32
  sy_l, sy_r = SPECIAL_SYMBOLS[0], SPECIAL_SYMBOLS[1]
33
  formatted_history = '\n'.join(f"{sy_l}{message}{sy_r}" for message in history)
34
  formatted_input = f"System: {sy_l}{instruction}{sy_r}\n{formatted_history}\n{sy_l}{input}{sy_r}\n{preinput}"
35
+ print(formatted_input)
36
  return formatted_input
37
 
38
  def predict(instruction, history, input, preinput, access_key, model, temperature, top_p, top_k, rep_p, max_tokens, stop_seqs, seed):
 
69
  history = history + [[input, get_result]]
70
 
71
  print(f"---\nUSER: {input}\nBOT: {get_result}\n---")
72
+
73
  return (get_result, input, history)
74
 
75
  def clear_history():
 
86
  with gr.Row():
87
  with gr.Column():
88
  history = gr.Chatbot(elem_id = "chatbot")
89
+ input = gr.Textbox(label = "Input", value = DEFAULT_INPUT, lines = 2)
90
+ preinput = gr.Textbox(label = "Pre-Input", value = DEFAULT_PREINPUT, lines = 1)
91
+ instruction = gr.Textbox(label = "Instruction", value = DEFAULT_INSTRUCTION, lines = 4)
92
  access_key = gr.Textbox(label = "Access Key", lines = 1)
93
  run = gr.Button("▶")
94
  clear = gr.Button("🗑️")