Spaces:
Sleeping
Sleeping
skylersterling
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -15,11 +15,12 @@ model.to('cpu')
|
|
15 |
|
16 |
# Define the function that generates text from a prompt
|
17 |
def generate_text(prompt, temperature, top_p):
|
18 |
-
|
|
|
19 |
input_tokens = input_tokens.to('cpu')
|
20 |
|
21 |
-
generated_text =
|
22 |
-
prompt_length = len(generated_text) # Capture the length of the initial prompt
|
23 |
|
24 |
for _ in range(80): # Adjust the range to control the number of tokens generated
|
25 |
with torch.no_grad():
|
@@ -40,7 +41,7 @@ def generate_text(prompt, temperature, top_p):
|
|
40 |
generated_text += decoded_token # Append the new token to the generated text
|
41 |
if decoded_token == "#": # Stop if the end of sequence token is generated
|
42 |
break
|
43 |
-
yield generated_text[prompt_length:] # Yield the generated text excluding the initial prompt
|
44 |
|
45 |
# Create a Gradio interface with a text input, sliders for temperature and top_p, and a text output
|
46 |
interface = gr.Interface(
|
|
|
15 |
|
16 |
# Define the function that generates text from a prompt
|
17 |
def generate_text(prompt, temperature, top_p):
|
18 |
+
prompt_with_eos = " #CONTEXT# " + prompt + " #TOPIC# " # Add the string "EOS" to the end of the prompt
|
19 |
+
input_tokens = tokenizer.encode(prompt_with_eos, return_tensors='pt')
|
20 |
input_tokens = input_tokens.to('cpu')
|
21 |
|
22 |
+
generated_text = prompt_with_eos # Start with the initial prompt plus "EOS"
|
23 |
+
prompt_length = len(generated_text) # Capture the length of the initial prompt plus "EOS"
|
24 |
|
25 |
for _ in range(80): # Adjust the range to control the number of tokens generated
|
26 |
with torch.no_grad():
|
|
|
41 |
generated_text += decoded_token # Append the new token to the generated text
|
42 |
if decoded_token == "#": # Stop if the end of sequence token is generated
|
43 |
break
|
44 |
+
yield generated_text[prompt_length:] # Yield the generated text excluding the initial prompt plus "EOS"
|
45 |
|
46 |
# Create a Gradio interface with a text input, sliders for temperature and top_p, and a text output
|
47 |
interface = gr.Interface(
|