RandomNameAnd6 commited on
Commit
71c1ec0
·
verified ·
1 Parent(s): cd23055

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -42,7 +42,7 @@ def levenshtein_distance(s1, s2):
42
 
43
  return previous_row[-1]
44
 
45
- def string_similarity_index(original_text, comparison_text, threshold=0.9):
46
  """
47
  Calculate the similarity index between two strings based on Levenshtein distance
48
  and compare it to a threshold.
@@ -67,13 +67,18 @@ def string_similarity_index(original_text, comparison_text, threshold=0.9):
67
  # Compare the similarity score to the threshold
68
  return similarity_score >= threshold
69
 
70
- def remove_suffix(input_string):
71
  if input_string.endswith(" | Dhar Mann"):
72
- return input_string[:-12]
73
  elif input_string.endswith(" | Dhar Mann Studios"):
74
- return input_string[:-20]
75
- else:
76
- return input_string
 
 
 
 
 
77
 
78
  # Function to generate an AI title
79
  def generate_ai_title():
@@ -86,7 +91,7 @@ def generate_ai_title():
86
  is_unique = True
87
  for title in dhar_mann_titles:
88
  title = title.strip() # Remove any extra whitespace characters like newlines
89
- if string_similarity_index(remove_suffix(generated_title), remove_suffix(title)):
90
  is_unique = False
91
  print(f"Regenerating! Generated title was: \"{generated_title}\", and the real title was \"{title}\"")
92
  break
 
42
 
43
  return previous_row[-1]
44
 
45
+ def string_similarity_index(original_text, comparison_text, threshold=0.75):
46
  """
47
  Calculate the similarity index between two strings based on Levenshtein distance
48
  and compare it to a threshold.
 
67
  # Compare the similarity score to the threshold
68
  return similarity_score >= threshold
69
 
70
+ def clean_title(input_string):
71
  if input_string.endswith(" | Dhar Mann"):
72
+ input_string = input_string[:-12]
73
  elif input_string.endswith(" | Dhar Mann Studios"):
74
+ input_string = input_string[:-20]
75
+
76
+ # Attempt to remove all text after the first comma
77
+ comma_index = input_string.find(',')
78
+ if comma_index != -1:
79
+ input_string = input_string[:comma_index]
80
+
81
+ return input_string
82
 
83
  # Function to generate an AI title
84
  def generate_ai_title():
 
91
  is_unique = True
92
  for title in dhar_mann_titles:
93
  title = title.strip() # Remove any extra whitespace characters like newlines
94
+ if string_similarity_index(clean_title(generated_title), clean_title(title)):
95
  is_unique = False
96
  print(f"Regenerating! Generated title was: \"{generated_title}\", and the real title was \"{title}\"")
97
  break