yentinglin commited on
Commit
ef219f6
1 Parent(s): 8c8e27f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +7 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,16 +1,17 @@
1
- import random
2
  import time
3
  import os
4
  import gradio as gr
5
  from text_generation import Client
6
  from conversation import get_default_conv_template
 
7
 
8
 
9
  endpoint_url = os.environ.get("ENDPOINT_URL", "http://127.0.0.1:8080")
10
  client = Client(endpoint_url, timeout=120)
11
  eos_token = "</s>"
 
12
 
13
-
14
 
15
  with gr.Blocks() as demo:
16
  chatbot = gr.Chatbot()
@@ -27,6 +28,10 @@ with gr.Blocks() as demo:
27
  conv.append_message(roles['human'], user)
28
  conv.append_message(roles["gpt"], bot)
29
  msg = conv.get_prompt()
 
 
 
 
30
 
31
  history[-1][1] = ""
32
  for response in client.generate_stream(
 
 
1
  import time
2
  import os
3
  import gradio as gr
4
  from text_generation import Client
5
  from conversation import get_default_conv_template
6
+ from transformers import AutoTokenizer
7
 
8
 
9
  endpoint_url = os.environ.get("ENDPOINT_URL", "http://127.0.0.1:8080")
10
  client = Client(endpoint_url, timeout=120)
11
  eos_token = "</s>"
12
+ max_prompt_length = 4000
13
 
14
+ tokenizer = AutoTokenizer.from_pretrained("yentinglin/Taiwan-LLaMa-v1.0")
15
 
16
  with gr.Blocks() as demo:
17
  chatbot = gr.Chatbot()
 
28
  conv.append_message(roles['human'], user)
29
  conv.append_message(roles["gpt"], bot)
30
  msg = conv.get_prompt()
31
+ prompt_tokens = tokenizer.encode(msg)
32
+ length_of_prompt = len(prompt_tokens)
33
+ if length_of_prompt > max_prompt_length:
34
+ msg = tokenizer.decode(prompt_tokens[-max_prompt_length:])
35
 
36
  history[-1][1] = ""
37
  for response in client.generate_stream(
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- text-generation==0.6.0
 
 
1
+ text-generation==0.6.0
2
+ transformers==4.31.0