Zenithwang commited on
Commit
bd0098f
1 Parent(s): 72f9be6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -33,7 +33,7 @@ sft_start_token = "<|im_start|>"
33
  sft_end_token = "<|im_end|>"
34
  ct_end_token = "<|endoftext|>"
35
 
36
- system_prompt= 'You are a CodeLLM developed by INF.'
37
 
38
 
39
  # Function to generate model predictions.
@@ -45,8 +45,8 @@ def predict(message, history):
45
  stop = StopOnTokens()
46
 
47
  model_messages = []
48
- print(f'history: {history}')
49
- model_messages.append({"role": system_role, "content": system_prompt})
50
  for i, item in enumerate(history):
51
  model_messages.append({"role": user_role, "content": item[0]})
52
  model_messages.append({"role": assistant_role, "content": item[1]})
@@ -55,7 +55,7 @@ def predict(message, history):
55
 
56
  print(f'model_messages: {model_messages}')
57
 
58
- print(f'model_final_inputs: {tokenizer.apply_chat_template(model_messages, add_generation_prompt=True, tokenize=False)}', flush=True)
59
  model_inputs = tokenizer.apply_chat_template(model_messages, add_generation_prompt=True, return_tensors="pt").to(device)
60
  # model_inputs = tokenizer([messages], return_tensors="pt").to(device)
61
 
@@ -64,7 +64,8 @@ def predict(message, history):
64
  input_ids=model_inputs,
65
  streamer=streamer,
66
  max_new_tokens=1024,
67
- do_sample=False
 
68
  )
69
 
70
  t = Thread(target=model.generate, kwargs=generate_kwargs)
@@ -87,24 +88,21 @@ full-height {
87
  """
88
 
89
  prompt_examples = [
90
- 'How to cook a fish?',
91
- 'Cara memanggang ikan',
92
- 'วิธีย่างปลา',
93
- 'Cách nướng cá'
94
  ]
95
 
96
  placeholder = """
97
  <div style="opacity: 0.5;">
98
- <img src="https://raw.githubusercontent.com/sail-sg/sailor-llm/main/misc/banner.jpg" style="width:30%;">
99
- <br>Sailor models are designed to understand and generate text across diverse linguistic landscapes of these SEA regions:
100
- <br>🇮🇩Indonesian, 🇹🇭Thai, 🇻🇳Vietnamese, 🇲🇾Malay, and 🇱🇦Lao.
101
  </div>
102
  """
103
 
104
- chatbot = gr.Chatbot(label='OpenCoder', placeholder=None)
 
105
  with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
106
- # gr.Markdown("""<center><font size=8>Sailor-Chat Bot⚓</center>""")
107
- gr.Markdown("""<p align="center"><img src="https://github.com/sail-sg/sailor-llm/raw/main/misc/wide_sailor_banner.jpg" style="height: 110px"/><p>""")
108
  gr.ChatInterface(predict, chatbot=chatbot, fill_height=True, examples=prompt_examples, css=css)
109
 
110
  demo.launch() # Launching the web interface.
 
33
  sft_end_token = "<|im_end|>"
34
  ct_end_token = "<|endoftext|>"
35
 
36
+ # system_prompt= 'You are a CodeLLM developed by INF.'
37
 
38
 
39
  # Function to generate model predictions.
 
45
  stop = StopOnTokens()
46
 
47
  model_messages = []
48
+ # print(f'history: {history}')
49
+
50
  for i, item in enumerate(history):
51
  model_messages.append({"role": user_role, "content": item[0]})
52
  model_messages.append({"role": assistant_role, "content": item[1]})
 
55
 
56
  print(f'model_messages: {model_messages}')
57
 
58
+ # print(f'model_final_inputs: {tokenizer.apply_chat_template(model_messages, add_generation_prompt=True, tokenize=False)}', flush=True)
59
  model_inputs = tokenizer.apply_chat_template(model_messages, add_generation_prompt=True, return_tensors="pt").to(device)
60
  # model_inputs = tokenizer([messages], return_tensors="pt").to(device)
61
 
 
64
  input_ids=model_inputs,
65
  streamer=streamer,
66
  max_new_tokens=1024,
67
+ do_sample=False,
68
+ stopping_criteria=StoppingCriteriaList([stop])
69
  )
70
 
71
  t = Thread(target=model.generate, kwargs=generate_kwargs)
 
88
  """
89
 
90
  prompt_examples = [
91
+ 'Write a quick sort algorithm in python.',
92
+ 'Write a colorful greedy snake game using pygame.',
93
+ 'How to use numpy?'
 
94
  ]
95
 
96
  placeholder = """
97
  <div style="opacity: 0.5;">
98
+ <img src="https://github.com/OpenCoder-llm/opencoder-llm.github.io/blob/main/static/images/opencoder_icon.jpg?raw=true" style="width:30%;">
 
 
99
  </div>
100
  """
101
 
102
+
103
+ chatbot = gr.Chatbot(label='OpenCoder', placeholder=placeholder)
104
  with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
105
+
 
106
  gr.ChatInterface(predict, chatbot=chatbot, fill_height=True, examples=prompt_examples, css=css)
107
 
108
  demo.launch() # Launching the web interface.