JeCabrera commited on
Commit
59b4bb9
verified
1 Parent(s): 2c60041

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -36
app.py CHANGED
@@ -14,59 +14,54 @@ def get_random_product_mention():
14
  probabilities = [0.34, 0.33, 0.33] # Probabilidades de cada menci贸n
15
  return random.choices(mentions, probabilities)[0]
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def get_gemini_response(target_audience, product, text_type, length, mood, model_choice):
18
- product_mention = get_random_product_mention() # Llamada correcta a la funci贸n
19
  model = genai.GenerativeModel(model_choice)
20
-
21
- # Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
22
- mention_instruction = ""
23
- if product_mention == "Directa":
24
- mention_instruction = f"""
25
- Directly introduce the product '{product}' as the clear solution to the problem the reader is facing. Ensure that the product is presented in a way that highlights its key benefits and demonstrates how it directly addresses the issue at hand. The mention should feel natural and seamlessly integrated into the narrative.
26
- """
27
- elif product_mention == "Indirecta":
28
- mention_instruction = f"""
29
- Subtly reference the product '{product}' as a potential solution to the reader's problem without naming it explicitly. Weave the product's core benefits into the description of how the reader can overcome the issue, creating an implicit connection between the solution and the product. Ensure the mention is subtle but clear enough to guide the reader towards the product.
30
- """
31
- elif product_mention == "Metaf贸rica":
32
- mention_instruction = f"""
33
- Introduce the product '{product}' using a metaphor, connecting it symbolically to the solution the reader needs. The metaphor should relate to the problem being discussed and should creatively suggest how the product offers a resolution without explicitly stating its name. The metaphor should evoke the benefits of the product in a memorable and thought-provoking way.
34
- """
35
 
36
  # Instrucci贸n espec铆fica para el tipo de texto
37
  format_instruction = ""
38
  if text_type == "Historia":
39
- format_instruction = """
40
- Write an engaging opening paragraph that introduces a relatable problem your audience is facing. Stir emotions by highlighting the impact of the problem on their life, and create curiosity with hints of a potential solution without revealing everything. Ensure that the narrative captivates the reader, leaving them wanting to discover how the story unfolds.
41
  """
42
  elif text_type == "Carta de venta":
43
- format_instruction = """
44
- Craft a persuasive lead paragraph for a sales letter that quickly identifies a common pain point your reader is experiencing. Agitate the problem by emphasizing the negative consequences of not addressing it, and tease the possibility of a solution to spark curiosity and compel the reader to continue reading for the answer.
45
  """
46
  elif text_type == "Correo":
47
- format_instruction = """
48
- Write a concise but impactful opening paragraph for an email that immediately captures the reader鈥檚 attention by acknowledging a challenge they are likely facing. Agitate the problem by emphasizing how it might be affecting their daily life, and leave them intrigued by hinting at a valuable solution that will be revealed if they continue reading.
49
  """
50
  elif text_type == "Landing page":
51
- format_instruction = """
52
- Design a compelling first paragraph for a landing page that immediately draws attention to a significant problem your target audience is encountering. Stir emotions by describing the frustrations or difficulties this issue causes and entice them to keep scrolling by subtly suggesting a solution without giving too much away.
53
  """
54
 
55
  # Crear el prompt completo basado en los campos del frontend
56
  full_prompt = f"""
57
- You are a creative writer skilled in the art of persuasion. The tone of the {text_type} should be {mood} and carefully crafted to emotionally resonate with a {target_audience}. {mention_instruction} {format_instruction} Use persuasive techniques to guide the reader towards an intuitive understanding of the product's benefits, focusing on creating a strong emotional connection with the audience.
58
- Create an opening paragraph for a {text_type} of {length} words in Spanish, that makes {target_audience} aware they have a problem by explaining it with real-life situations, using a natural or conversational tone. The goal of this paragraph is to make them want to keep reading and find out what {product} is about. Use persuasion effectively in every word, mastering advanced techniques like using powerful headlines and intriguing openings.
59
-
60
- To write this opening paragraph, use one or more of these Copywriting Techniques, choosing the most appropriate ones:
61
-
62
- 1. If/Then: This is one of the most commonly used opening paragraphs. Gary Halbert, one of the most important copywriters of the 20th century, used them in almost every one of his sales letters. It鈥檚 very simple, clear, and powerful. It lets people know what to expect. There鈥檚 also a very interesting belief structure that is built with this combo. If this, then that. It鈥檚 as if they need to meet some kind of prerequisite to get the benefit. An example of this would be: 'If you want to make more than $100,000 a year working just 4 hours a day, then this letter will show you how.' Very simple. If you want that, then here鈥檚 how you do it.
63
- 2. If / Then + Authority: Even more powerful than the 'If / Then' key is the same concept but adding a figure of authority or credibility. For example: 'If you want to know a secret way to become almost invincible in a fight... then here I鈥檒l show you what the gladiators and samurais used to do. And why you can do it too starting today.' One way to notice the power of these opening paragraphs is by removing the authority figure. In this case: the gladiators and samurais. That would change the paragraph to: 'If you want to know a secret way to become almost invincible in a fight... then here I鈥檒l show you why you can do it too starting today.' As you can see, it doesn鈥檛 have as much impact as the version with the gladiators and samurais.
64
- 3. Honesty: Being transparent is one of the best ways to get more customers. It also works with opening paragraphs. For example, one of Gary Halbert鈥檚 ads started like this: 'My name is Betty Adams, and the first thing you should know about me is... I鈥檓 not a doctor. I鈥檓 also not a nutrition expert. I didn鈥檛 go to college and I don鈥檛 even have a degree. In fact, the only thing I consider myself an expert in is...' And then it went to a subheading where she mentioned how she could help you lose 10 kilos in a very simple way. In this case, you can notice all the negatives she uses: 'I鈥檓 not a doctor,' 'I鈥檓 not a nutrition expert,' 'I didn鈥檛 go to school,' 'I don鈥檛 have a degree.' These four negative statements strengthen her claim about what she is. Now, this won鈥檛 always work for every sales letter. It will depend on your market and ideal customer. If your market isn鈥檛 skeptical, you don鈥檛 need to use this kind of paragraph.
65
- 4. Sensationalist: This one is related to the sensational headline. Here鈥檚 where you鈥檇 say something like: 'Let me tell you this strange story about a man who was arrested because he had herpes.' It鈥檚 sensationalist. And sensationalism sells. It always has and always will. Without a doubt, the paragraph is strange and makes your reader think: 'How was someone arrested for having herpes? What did he do? What happened?' It keeps them hooked, addicted to finding out more. They need to know.
66
- 5. Ask a Question: It makes people stop if they鈥檙e interested. One of the best opening paragraphs is this: 'Did you know that the long-term value of baseball cards is much higher than that of stocks and rare coins?' So when you talk to someone in the finance, investor, or related niches about this topic, they will be interested because it鈥檚 different and gets them ready to start the journey.
67
- 6. Micro Openings: This paragraph should be short. Just a few words... so they鈥檒l read the next one. This is because being brief makes it easy to read. And if you say something that puts your reader in the right mindset, this can be quite powerful. For example, if your product is targeted to a skeptical market, you can use a paragraph like the following: 'I was a total skeptic.' With this, you鈥檙e going straight to their mind, to their doubts. One that you can use effectively is: 'Imagine the following:'
68
  """
69
-
70
  response = model.generate_content([full_prompt])
71
 
72
  # Comprobar si la respuesta es v谩lida y devolver el texto
 
14
  probabilities = [0.34, 0.33, 0.33] # Probabilidades de cada menci贸n
15
  return random.choices(mentions, probabilities)[0]
16
 
17
+ # Funci贸n para obtener una t茅cnica de copywriting de manera aleatoria
18
+ def get_random_copywriting_technique():
19
+ techniques = [
20
+ "If/Then: This is one of the most commonly used opening paragraphs. It鈥檚 very simple, clear, and powerful.",
21
+ "If / Then + Authority: Adding a figure of authority or credibility to the opening.",
22
+ "Honesty: Being transparent is one of the best ways to get more customers.",
23
+ "Sensationalist: It grabs attention with unusual or provocative statements.",
24
+ "Ask a Question: It makes people stop if they鈥檙e interested.",
25
+ "Micro Openings: Keep it brief to encourage further reading."
26
+ ]
27
+ return random.sample(techniques, k=random.randint(1, 3)) # Escoge entre 1 y 3 t茅cnicas al azar
28
+
29
+ # Al crear el prompt completo, incluye el tama帽o y las t茅cnicas seleccionadas
30
  def get_gemini_response(target_audience, product, text_type, length, mood, model_choice):
31
+ product_mention = get_random_product_mention()
32
  model = genai.GenerativeModel(model_choice)
33
+
34
+ # Obtener t茅cnicas aleatorias
35
+ copywriting_techniques = get_random_copywriting_technique()
36
+ techniques_text = " ".join(copywriting_techniques)
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  # Instrucci贸n espec铆fica para el tipo de texto
39
  format_instruction = ""
40
  if text_type == "Historia":
41
+ format_instruction = f"""
42
+ Write an engaging opening paragraph that introduces a relatable problem your audience is facing. Stir emotions by highlighting the impact of the problem on their life, and create curiosity with hints of a potential solution without revealing everything. The paragraph should be approximately {length} words long to maintain engagement and avoid losing the reader's attention.
43
  """
44
  elif text_type == "Carta de venta":
45
+ format_instruction = f"""
46
+ Craft a persuasive lead paragraph for a sales letter that quickly identifies a common pain point your reader is experiencing. The paragraph should be around {length} words long and agitate the problem by emphasizing the negative consequences of not addressing it, and tease the possibility of a solution to spark curiosity.
47
  """
48
  elif text_type == "Correo":
49
+ format_instruction = f"""
50
+ Write a concise but impactful opening paragraph for an email that captures the reader鈥檚 attention. The text should be approximately {length} words, addressing a challenge they are likely facing, and leave them intrigued by hinting at a valuable solution that will be revealed if they continue reading.
51
  """
52
  elif text_type == "Landing page":
53
+ format_instruction = f"""
54
+ Design a compelling first paragraph for a landing page that immediately draws attention to a significant problem your target audience is encountering. The paragraph should be about {length} words long, stirring emotions and enticing them to keep scrolling by subtly suggesting a solution.
55
  """
56
 
57
  # Crear el prompt completo basado en los campos del frontend
58
  full_prompt = f"""
59
+ You are a creative writer skilled in the art of persuasion. The tone of the {text_type} should be {mood} and carefully crafted to emotionally resonate with a {target_audience}. {mention_instruction} {format_instruction}
60
+ Incorporate the following copywriting techniques: {techniques_text}
61
+ Use persuasive techniques to guide the reader towards an intuitive understanding of the product's benefits, focusing on creating a strong emotional connection with the audience.
62
+ Create an opening paragraph for a {text_type} of {length} words in Spanish, that makes {target_audience} aware they have a problem by explaining it with real-life situations, using a natural or conversational tone. The goal of this paragraph is to make them want to keep reading and find out what {product} is about. Use persuasion effectively in every word, mastering advanced techniques.
 
 
 
 
 
 
 
63
  """
64
+
65
  response = model.generate_content([full_prompt])
66
 
67
  # Comprobar si la respuesta es v谩lida y devolver el texto