Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,8 @@ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
|
8 |
|
9 |
# Function to generate keywords based on a prompt
|
10 |
def generate_keywords(prompt):
|
11 |
-
# Encode input prompt with
|
12 |
-
prompt_with_instruction = prompt + "
|
13 |
inputs = tokenizer.encode(prompt_with_instruction, return_tensors="pt")
|
14 |
|
15 |
# Generate output from model
|
@@ -18,10 +18,12 @@ def generate_keywords(prompt):
|
|
18 |
# Decode generated tokens
|
19 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
23 |
|
24 |
-
|
|
|
25 |
|
26 |
# Gradio interface
|
27 |
iface = gr.Interface(fn=generate_keywords,
|
|
|
8 |
|
9 |
# Function to generate keywords based on a prompt
|
10 |
def generate_keywords(prompt):
|
11 |
+
# Encode input prompt with a more direct instruction for only keywords
|
12 |
+
prompt_with_instruction = prompt + " Only provide a list of keywords, no additional text."
|
13 |
inputs = tokenizer.encode(prompt_with_instruction, return_tensors="pt")
|
14 |
|
15 |
# Generate output from model
|
|
|
18 |
# Decode generated tokens
|
19 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
|
21 |
+
# Clean up the text to remove unnecessary parts
|
22 |
+
# Remove anything after 'Only provide a list of keywords'
|
23 |
+
clean_text = generated_text.split("Only provide a list of keywords")[0].strip()
|
24 |
|
25 |
+
# Return the keywords only
|
26 |
+
return clean_text
|
27 |
|
28 |
# Gradio interface
|
29 |
iface = gr.Interface(fn=generate_keywords,
|