Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,22 +2,18 @@ import warnings
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# Ignore specific warnings
|
6 |
warnings.filterwarnings("ignore", category=FutureWarning, module="transformers.tokenization_utils_base")
|
7 |
|
8 |
-
|
9 |
-
model_name = "EleutherAI/gpt-neo-1.3B" # Use a lightweight model
|
10 |
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_length=100):
|
15 |
inputs = tokenizer(prompt, return_tensors="pt")
|
16 |
outputs = model.generate(inputs.input_ids, max_length=max_length, do_sample=True, top_p=0.95, temperature=0.7)
|
17 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
18 |
return text
|
19 |
|
20 |
-
# Function to generate situations and copy according to user selections
|
21 |
def generate_situations_and_copys(stage, product, situation):
|
22 |
prompt = f"""
|
23 |
Est谩s creando una campa帽a publicitaria para la etapa {stage} del funnel de marketing. El producto es: {product}.
|
@@ -26,12 +22,6 @@ def generate_situations_and_copys(stage, product, situation):
|
|
26 |
"""
|
27 |
return generate_text(prompt)
|
28 |
|
29 |
-
# Gradio Interface
|
30 |
-
def main(stage, product, situation):
|
31 |
-
generated_copys = generate_situations_and_copys(stage, product, situation)
|
32 |
-
return generated_copys
|
33 |
-
|
34 |
-
# Dropdown options for Gradio
|
35 |
stages = ["Upper", "Middle", "Lower"]
|
36 |
products = {
|
37 |
"Upper": ["Convierte tu tel茅fono en un POS", "M谩s de 700 plantillas web con Wix"],
|
@@ -53,33 +43,37 @@ situations = {
|
|
53 |
]
|
54 |
}
|
55 |
|
56 |
-
def
|
57 |
-
return
|
|
|
|
|
|
|
58 |
|
59 |
-
def
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
# Gradio App Interface
|
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",
|
68 |
-
product_input = gr.Dropdown(choices=[], label="Producto"
|
69 |
-
situation_input = gr.Dropdown(choices=[], label="Situaci贸n"
|
70 |
|
71 |
-
stage_input.change(
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
output_text = gr.Textbox(label="Copys Generados")
|
76 |
|
77 |
-
generate_button.click(
|
78 |
|
79 |
-
# Optional Custom Prompt Section
|
80 |
custom_prompt_input = gr.Textbox(label="Ingresa un prompt para personalizar el copy", value="")
|
81 |
-
generate_custom_button = gr.Button("Generar
|
82 |
-
custom_output_text = gr.Textbox(label="
|
83 |
|
84 |
generate_custom_button.click(fn=generate_text, inputs=custom_prompt_input, outputs=custom_output_text)
|
85 |
|
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import gradio as gr
|
4 |
|
|
|
5 |
warnings.filterwarnings("ignore", category=FutureWarning, module="transformers.tokenization_utils_base")
|
6 |
|
7 |
+
model_name = "EleutherAI/gpt-neo-1.3B"
|
|
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
|
|
|
11 |
def generate_text(prompt, max_length=100):
|
12 |
inputs = tokenizer(prompt, return_tensors="pt")
|
13 |
outputs = model.generate(inputs.input_ids, max_length=max_length, do_sample=True, top_p=0.95, temperature=0.7)
|
14 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
15 |
return text
|
16 |
|
|
|
17 |
def generate_situations_and_copys(stage, product, situation):
|
18 |
prompt = f"""
|
19 |
Est谩s creando una campa帽a publicitaria para la etapa {stage} del funnel de marketing. El producto es: {product}.
|
|
|
22 |
"""
|
23 |
return generate_text(prompt)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
stages = ["Upper", "Middle", "Lower"]
|
26 |
products = {
|
27 |
"Upper": ["Convierte tu tel茅fono en un POS", "M谩s de 700 plantillas web con Wix"],
|
|
|
43 |
]
|
44 |
}
|
45 |
|
46 |
+
def get_products(stage):
|
47 |
+
return products[stage]
|
48 |
+
|
49 |
+
def get_situations(stage):
|
50 |
+
return situations[stage]
|
51 |
|
52 |
+
def main(stage):
|
53 |
+
product_choices = get_products(stage)
|
54 |
+
situation_choices = get_situations(stage)
|
55 |
+
|
56 |
+
# Return default selections for product and situation
|
57 |
+
return gr.Dropdown.update(choices=product_choices, value=product_choices[0]), gr.Dropdown.update(choices=situation_choices, value=situation_choices[0])
|
58 |
|
|
|
59 |
with gr.Blocks() as demo:
|
60 |
+
gr.Markdown("# Herramienta de Generaci贸n de Copies Publicitarios")
|
61 |
|
62 |
with gr.Row():
|
63 |
+
stage_input = gr.Dropdown(choices=stages, label="Etapa del Funnel", value="Upper")
|
64 |
+
product_input = gr.Dropdown(choices=[], label="Producto")
|
65 |
+
situation_input = gr.Dropdown(choices=[], label="Situaci贸n")
|
66 |
|
67 |
+
stage_input.change(main, inputs=[stage_input], outputs=[product_input, situation_input])
|
68 |
+
|
69 |
+
generate_button = gr.Button("Generar Copies")
|
70 |
+
output_text = gr.Textbox(label="Copies Generados")
|
|
|
71 |
|
72 |
+
generate_button.click(generate_situations_and_copys, inputs=[stage_input, product_input, situation_input], outputs=output_text)
|
73 |
|
|
|
74 |
custom_prompt_input = gr.Textbox(label="Ingresa un prompt para personalizar el copy", value="")
|
75 |
+
generate_custom_button = gr.Button("Generar Copies Personalizados")
|
76 |
+
custom_output_text = gr.Textbox(label="Copies Personalizados")
|
77 |
|
78 |
generate_custom_button.click(fn=generate_text, inputs=custom_prompt_input, outputs=custom_output_text)
|
79 |
|