skylersterling commited on
Commit
f7d422b
·
verified ·
1 Parent(s): 9b45f2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -17,6 +17,11 @@ def generate_text(prompt, temperature):
17
  word_count = len(prompt.split())
18
  if word_count < 5:
19
  return "Please provide at least 5 words in the prompt."
 
 
 
 
 
20
 
21
  prompt_with_eos = "#CONTEXT# " + prompt + " #TOPIC# " # Add the string "EOS" to the end of the prompt
22
  input_tokens = tokenizer.encode(prompt_with_eos, return_tensors='pt')
@@ -52,4 +57,4 @@ interface = gr.Interface(
52
  description="TopicGPT processes the input and returns a reasonably accurate guess of the topic/theme of a given conversation."
53
  )
54
 
55
- interface.launch()
 
17
  word_count = len(prompt.split())
18
  if word_count < 5:
19
  return "Please provide at least 5 words in the prompt."
20
+
21
+ # Tokenize the prompt to check the number of tokens
22
+ input_tokens = tokenizer.encode(prompt, return_tensors='pt')
23
+ if input_tokens.size(1) > 512:
24
+ return "Please provide an input with fewer than 512 tokens."
25
 
26
  prompt_with_eos = "#CONTEXT# " + prompt + " #TOPIC# " # Add the string "EOS" to the end of the prompt
27
  input_tokens = tokenizer.encode(prompt_with_eos, return_tensors='pt')
 
57
  description="TopicGPT processes the input and returns a reasonably accurate guess of the topic/theme of a given conversation."
58
  )
59
 
60
+ interface.launch()