Spaces:
Sleeping
Sleeping
Update formulas.py
Browse files- formulas.py +0 -59
formulas.py
CHANGED
|
@@ -15,62 +15,6 @@ CRITICAL OUTPUT RULES:
|
|
| 15 |
- Do not add any characters that could trigger text box formatting
|
| 16 |
"""
|
| 17 |
|
| 18 |
-
def extract_product_name(product_name_input):
|
| 19 |
-
"""
|
| 20 |
-
Extracts the actual product name from user input, especially when it's enclosed in quotes.
|
| 21 |
-
|
| 22 |
-
Args:
|
| 23 |
-
product_name_input: The raw input string containing the product name
|
| 24 |
-
|
| 25 |
-
Returns:
|
| 26 |
-
str: The extracted product name, or empty string if generic
|
| 27 |
-
"""
|
| 28 |
-
import re
|
| 29 |
-
|
| 30 |
-
# If input is empty or None, return empty string
|
| 31 |
-
if not product_name_input or product_name_input.strip() == "":
|
| 32 |
-
return ""
|
| 33 |
-
|
| 34 |
-
# Check if there's a name in quotes
|
| 35 |
-
quote_pattern = r'"([^"]+)"'
|
| 36 |
-
matches = re.findall(quote_pattern, product_name_input)
|
| 37 |
-
|
| 38 |
-
if matches:
|
| 39 |
-
# Return the first quoted string found
|
| 40 |
-
return matches[0]
|
| 41 |
-
|
| 42 |
-
# If no quotes but contains "llamado" or similar phrases, extract what follows
|
| 43 |
-
called_patterns = [
|
| 44 |
-
r'llamado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)',
|
| 45 |
-
r'titulado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)',
|
| 46 |
-
r'denominado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)',
|
| 47 |
-
r'nombrado\s+(.+?)(?:\s+que|\s+con|\s+para|\.$|$)'
|
| 48 |
-
]
|
| 49 |
-
|
| 50 |
-
for pattern in called_patterns:
|
| 51 |
-
matches = re.search(pattern, product_name_input, re.IGNORECASE)
|
| 52 |
-
if matches:
|
| 53 |
-
extracted = matches.group(1).strip()
|
| 54 |
-
# If the extracted text has quotes, remove them
|
| 55 |
-
if extracted.startswith('"') and extracted.endswith('"'):
|
| 56 |
-
extracted = extracted[1:-1]
|
| 57 |
-
return extracted
|
| 58 |
-
|
| 59 |
-
# Check if the input is generic (common course/product types without specific names)
|
| 60 |
-
generic_patterns = [
|
| 61 |
-
r'^(curso|taller|programa|webinar|entrenamiento|sistema|m茅todo|servicio|producto|aplicaci贸n|comunidad|masterclass)(\s+de\s+.+)?$',
|
| 62 |
-
r'^(un|el|mi|nuestro)\s+(curso|taller|programa|webinar|entrenamiento|sistema|m茅todo|servicio|producto|aplicaci贸n|comunidad|masterclass)(\s+de\s+.+)?$'
|
| 63 |
-
]
|
| 64 |
-
|
| 65 |
-
for pattern in generic_patterns:
|
| 66 |
-
if re.match(pattern, product_name_input.lower(), re.IGNORECASE):
|
| 67 |
-
# This is a generic description, return empty string to trigger creative name generation
|
| 68 |
-
return ""
|
| 69 |
-
|
| 70 |
-
# If no patterns match, return the original input
|
| 71 |
-
return product_name_input.strip()
|
| 72 |
-
|
| 73 |
-
|
| 74 |
def create_offer_instruction(avatar_description, product_name, selected_formula_name):
|
| 75 |
"""
|
| 76 |
Creates instructions for generating an offer based on the selected formula.
|
|
@@ -83,9 +27,6 @@ def create_offer_instruction(avatar_description, product_name, selected_formula_
|
|
| 83 |
Returns:
|
| 84 |
str: Complete instruction for generating the offer
|
| 85 |
"""
|
| 86 |
-
# Extract the actual product name if it's in quotes or after "llamado"
|
| 87 |
-
extracted_name = extract_product_name(product_name)
|
| 88 |
-
|
| 89 |
# Get the selected formula
|
| 90 |
selected_formula = offer_formulas[selected_formula_name]
|
| 91 |
|
|
|
|
| 15 |
- Do not add any characters that could trigger text box formatting
|
| 16 |
"""
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def create_offer_instruction(avatar_description, product_name, selected_formula_name):
|
| 19 |
"""
|
| 20 |
Creates instructions for generating an offer based on the selected formula.
|
|
|
|
| 27 |
Returns:
|
| 28 |
str: Complete instruction for generating the offer
|
| 29 |
"""
|
|
|
|
|
|
|
|
|
|
| 30 |
# Get the selected formula
|
| 31 |
selected_formula = offer_formulas[selected_formula_name]
|
| 32 |
|