KhantKyaw commited on
Commit
ec318c7
1 Parent(s): 1d2d749

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,6 +1,13 @@
1
  import streamlit as st
2
 
3
  from transformers import GPT2Tokenizer, GPT2LMHeadModel
 
 
 
 
 
 
 
4
 
5
  # Function to generate a response
6
  def generate_response(input_text):
@@ -20,6 +27,7 @@ def generate_response(input_text):
20
  top_p=0.95,
21
  no_repeat_ngram_size=2,
22
  pad_token_id=tokenizer.eos_token_id,
 
23
  #early_stopping=True,
24
  do_sample=True
25
  )
@@ -30,20 +38,14 @@ def generate_response(input_text):
30
  # Extract the generated response after the [Bot] marker
31
  bot_response_start = full_generated_text.find('[Bot]') + len('[Bot]')
32
  bot_response = full_generated_text[bot_response_start:]
33
-
34
- # Trim the response to end at the last period within the specified max_length
35
- last_period_index = bot_response.rfind('.')
36
- if last_period_index != -1:
37
- bot_response = bot_response[:last_period_index + 1]
38
-
39
- return bot_response.strip()
40
 
41
  # Load pre-trained model tokenizer (vocabulary) and model
42
  model_name = 'KhantKyaw/Chat_GPT-2'
43
  tokenizer = GPT2Tokenizer.from_pretrained(model_name)
44
  model = GPT2LMHeadModel.from_pretrained(model_name)
45
 
46
- st.title("Echo Bot")
47
 
48
  # Initialize chat history
49
  if "messages" not in st.session_state:
 
1
  import streamlit as st
2
 
3
  from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
+ model_name = 'KhantKyaw/Chat_GPT-2'
5
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
6
+ model = GPT2LMHeadModel.from_pretrained(model_name)
7
+
8
+ special_tokens_dict = {'bos_token': '<BOS>', 'eos_token': '<EOS>', 'sep_token': '<SEP>', 'pad_token': '<PAD>'}
9
+ tokenizer.add_special_tokens(special_tokens_dict)
10
+ model.resize_token_embeddings(len(tokenizer))
11
 
12
  # Function to generate a response
13
  def generate_response(input_text):
 
27
  top_p=0.95,
28
  no_repeat_ngram_size=2,
29
  pad_token_id=tokenizer.eos_token_id,
30
+ eos_token_id=tokenizer.eos_token_id,
31
  #early_stopping=True,
32
  do_sample=True
33
  )
 
38
  # Extract the generated response after the [Bot] marker
39
  bot_response_start = full_generated_text.find('[Bot]') + len('[Bot]')
40
  bot_response = full_generated_text[bot_response_start:]
41
+ return bot_response
 
 
 
 
 
 
42
 
43
  # Load pre-trained model tokenizer (vocabulary) and model
44
  model_name = 'KhantKyaw/Chat_GPT-2'
45
  tokenizer = GPT2Tokenizer.from_pretrained(model_name)
46
  model = GPT2LMHeadModel.from_pretrained(model_name)
47
 
48
+ st.title("Chat_GPT-2 Bot")
49
 
50
  # Initialize chat history
51
  if "messages" not in st.session_state: