Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,25 +11,32 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
12 |
|
13 |
# Function to generate text
|
14 |
-
def generate_text(prompt, max_new_tokens=
|
15 |
inputs = tokenizer(prompt, return_tensors="pt")
|
16 |
outputs = model.generate(
|
17 |
inputs.input_ids,
|
18 |
max_new_tokens=max_new_tokens,
|
19 |
do_sample=True,
|
|
|
20 |
top_p=0.95,
|
21 |
-
temperature=0.
|
22 |
pad_token_id=tokenizer.eos_token_id # Ensure correct behavior for padding
|
23 |
)
|
24 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
25 |
return text
|
26 |
|
27 |
# Function to generate situations and copy according to user selections
|
28 |
-
def
|
29 |
prompt = f"""
|
30 |
Est谩s creando una campa帽a publicitaria para la etapa {stage} del funnel de marketing. El producto es: {product}.
|
31 |
La situaci贸n cotidiana es: {situation}. Integra el concepto de marca "T煤 eliges" en el copy.
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
"""
|
34 |
return generate_text(prompt)
|
35 |
|
@@ -61,7 +68,7 @@ def update_dropdowns(stage):
|
|
61 |
return gr.Dropdown.update(choices=product_choices), gr.Dropdown.update(choices=situation_choices)
|
62 |
|
63 |
with gr.Blocks() as demo:
|
64 |
-
gr.Markdown("# Herramienta de Generaci贸n de
|
65 |
|
66 |
with gr.Row():
|
67 |
stage_input = gr.Dropdown(choices=stages, label="Etapa del Funnel", value="Upper")
|
@@ -70,14 +77,14 @@ with gr.Blocks() as demo:
|
|
70 |
|
71 |
stage_input.change(fn=update_dropdowns, inputs=stage_input, outputs=[product_input, situation_input])
|
72 |
|
73 |
-
generate_button = gr.Button("Generar
|
74 |
-
output_text = gr.Textbox(label="
|
75 |
|
76 |
-
generate_button.click(fn=
|
77 |
|
78 |
custom_prompt_input = gr.Textbox(label="Ingresa un prompt para personalizar el copy", value="")
|
79 |
-
generate_custom_button = gr.Button("Generar
|
80 |
-
custom_output_text = gr.Textbox(label="
|
81 |
|
82 |
generate_custom_button.click(fn=generate_text, inputs=custom_prompt_input, outputs=custom_output_text)
|
83 |
|
|
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
12 |
|
13 |
# Function to generate text
|
14 |
+
def generate_text(prompt, max_new_tokens=200):
|
15 |
inputs = tokenizer(prompt, return_tensors="pt")
|
16 |
outputs = model.generate(
|
17 |
inputs.input_ids,
|
18 |
max_new_tokens=max_new_tokens,
|
19 |
do_sample=True,
|
20 |
+
top_k=50, # Consider only the top 50 tokens for sampling
|
21 |
top_p=0.95,
|
22 |
+
temperature=0.8, # Increase diversity slightly
|
23 |
pad_token_id=tokenizer.eos_token_id # Ensure correct behavior for padding
|
24 |
)
|
25 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
26 |
return text
|
27 |
|
28 |
# Function to generate situations and copy according to user selections
|
29 |
+
def generate_situations_and_copies(stage, product, situation):
|
30 |
prompt = f"""
|
31 |
Est谩s creando una campa帽a publicitaria para la etapa {stage} del funnel de marketing. El producto es: {product}.
|
32 |
La situaci贸n cotidiana es: {situation}. Integra el concepto de marca "T煤 eliges" en el copy.
|
33 |
+
|
34 |
+
Genera 5 opciones de copy (titular y bajada) en espa帽ol:
|
35 |
+
1.
|
36 |
+
2.
|
37 |
+
3.
|
38 |
+
4.
|
39 |
+
5.
|
40 |
"""
|
41 |
return generate_text(prompt)
|
42 |
|
|
|
68 |
return gr.Dropdown.update(choices=product_choices), gr.Dropdown.update(choices=situation_choices)
|
69 |
|
70 |
with gr.Blocks() as demo:
|
71 |
+
gr.Markdown("# Herramienta de Generaci贸n de Copies Publicitarios")
|
72 |
|
73 |
with gr.Row():
|
74 |
stage_input = gr.Dropdown(choices=stages, label="Etapa del Funnel", value="Upper")
|
|
|
77 |
|
78 |
stage_input.change(fn=update_dropdowns, inputs=stage_input, outputs=[product_input, situation_input])
|
79 |
|
80 |
+
generate_button = gr.Button("Generar Copies")
|
81 |
+
output_text = gr.Textbox(label="Copies Generados")
|
82 |
|
83 |
+
generate_button.click(fn=generate_situations_and_copies, inputs=[stage_input, product_input, situation_input], outputs=output_text)
|
84 |
|
85 |
custom_prompt_input = gr.Textbox(label="Ingresa un prompt para personalizar el copy", value="")
|
86 |
+
generate_custom_button = gr.Button("Generar Copies Personalizados")
|
87 |
+
custom_output_text = gr.Textbox(label="Copies Personalizados")
|
88 |
|
89 |
generate_custom_button.click(fn=generate_text, inputs=custom_prompt_input, outputs=custom_output_text)
|
90 |
|