RandomNameAnd6 commited on
Commit
80529b7
1 Parent(s): 3d74dd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -75,14 +75,21 @@ def string_similarity_index(original_text, comparison_text, threshold=0.6):
75
 
76
  # Function to generate an AI title
77
  def generate_ai_title():
78
- inputs = tokenizer(["<|startoftext|>"]*1, return_tensors = "pt")
79
- outputs = model.generate(**inputs, max_new_tokens=50, use_cache=True, temperature=0.85, do_sample=True)
80
- generated_title = (tokenizer.batch_decode(outputs)[0])[15:-13]
81
- for title in dhar_mann_titles:
82
- title = title.strip() # Remove any extra whitespace characters like newlines
83
- if string_similarity_index(generated_title, title):
84
- return generate_ai_title()
85
- return generated_title
 
 
 
 
 
 
 
86
 
87
  # Function to check user's answer and update score
88
  def check_answer(user_choice, real_index, score):
 
75
 
76
  # Function to generate an AI title
77
  def generate_ai_title():
78
+ while True:
79
+ inputs = tokenizer(["<|startoftext|>"]*1, return_tensors="pt")
80
+ outputs = model.generate(**inputs, max_new_tokens=48, use_cache=True, temperature=0.85, do_sample=True)
81
+ generated_title = (tokenizer.batch_decode(outputs)[0])[15:-13].strip()
82
+
83
+ # Check for similarity with existing titles
84
+ is_unique = True
85
+ for title in dhar_mann_titles:
86
+ title = title.strip() # Remove any extra whitespace characters like newlines
87
+ if string_similarity_index(generated_title, title):
88
+ is_unique = False
89
+ break
90
+
91
+ if is_unique:
92
+ return generated_title
93
 
94
  # Function to check user's answer and update score
95
  def check_answer(user_choice, real_index, score):