Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,9 +12,16 @@ model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
12 |
|
13 |
# Function to generate text
|
14 |
def generate_text(prompt, max_new_tokens=200):
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
@@ -22,6 +29,8 @@ def generate_text(prompt, max_new_tokens=200):
|
|
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 |
|
@@ -67,7 +76,57 @@ def update_dropdowns(stage):
|
|
67 |
situation_choices = situations[stage]
|
68 |
return gr.Dropdown.update(choices=product_choices), gr.Dropdown.update(choices=situation_choices)
|
69 |
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
gr.Markdown("# Herramienta de Generaci贸n de Copies Publicitarios")
|
72 |
|
73 |
with gr.Row():
|
@@ -83,7 +142,7 @@ with gr.Blocks() as demo:
|
|
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)
|
|
|
12 |
|
13 |
# Function to generate text
|
14 |
def generate_text(prompt, max_new_tokens=200):
|
15 |
+
# Tokenize the input prompt
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True)
|
17 |
+
|
18 |
+
# Create an attention mask
|
19 |
+
attention_mask = inputs.attention_mask
|
20 |
+
|
21 |
+
# Generate the text using the model
|
22 |
outputs = model.generate(
|
23 |
inputs.input_ids,
|
24 |
+
attention_mask=attention_mask, # Pass the attention mask
|
25 |
max_new_tokens=max_new_tokens,
|
26 |
do_sample=True,
|
27 |
top_k=50, # Consider only the top 50 tokens for sampling
|
|
|
29 |
temperature=0.8, # Increase diversity slightly
|
30 |
pad_token_id=tokenizer.eos_token_id # Ensure correct behavior for padding
|
31 |
)
|
32 |
+
|
33 |
+
# Decode the output text
|
34 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
35 |
return text
|
36 |
|
|
|
76 |
situation_choices = situations[stage]
|
77 |
return gr.Dropdown.update(choices=product_choices), gr.Dropdown.update(choices=situation_choices)
|
78 |
|
79 |
+
# Custom CSS for design
|
80 |
+
custom_css = """
|
81 |
+
#app {
|
82 |
+
background-color: white;
|
83 |
+
color: #333;
|
84 |
+
}
|
85 |
+
|
86 |
+
.gradio-container {
|
87 |
+
font-family: 'Helvetica Neue', sans-serif;
|
88 |
+
}
|
89 |
+
|
90 |
+
.gr-button {
|
91 |
+
background-color: #ff4240;
|
92 |
+
color: white;
|
93 |
+
border: none;
|
94 |
+
padding: 10px 20px;
|
95 |
+
font-weight: bold;
|
96 |
+
transition: background-color 0.3s ease;
|
97 |
+
}
|
98 |
+
|
99 |
+
.gr-button:hover {
|
100 |
+
background-color: #e03a3a;
|
101 |
+
}
|
102 |
+
|
103 |
+
.gr-button-secondary {
|
104 |
+
background-color: #3dd2ce;
|
105 |
+
color: white;
|
106 |
+
border: none;
|
107 |
+
padding: 10px 20px;
|
108 |
+
font-weight: bold;
|
109 |
+
transition: background-color 0.3s ease;
|
110 |
+
}
|
111 |
+
|
112 |
+
.gr-button-secondary:hover {
|
113 |
+
background-color: #37bebc;
|
114 |
+
}
|
115 |
+
|
116 |
+
.gr-textbox, .gr-dropdown {
|
117 |
+
border: 2px solid #3dd2ce;
|
118 |
+
border-radius: 5px;
|
119 |
+
padding: 8px;
|
120 |
+
}
|
121 |
+
|
122 |
+
.gr-textbox:focus, .gr-dropdown:focus {
|
123 |
+
border-color: #ff4240;
|
124 |
+
box-shadow: 0 0 5px rgba(255, 66, 64, 0.5);
|
125 |
+
}
|
126 |
+
"""
|
127 |
+
|
128 |
+
# Gradio Interface with CSS styling
|
129 |
+
with gr.Blocks(css=custom_css) as demo:
|
130 |
gr.Markdown("# Herramienta de Generaci贸n de Copies Publicitarios")
|
131 |
|
132 |
with gr.Row():
|
|
|
142 |
generate_button.click(fn=generate_situations_and_copies, inputs=[stage_input, product_input, situation_input], outputs=output_text)
|
143 |
|
144 |
custom_prompt_input = gr.Textbox(label="Ingresa un prompt para personalizar el copy", value="")
|
145 |
+
generate_custom_button = gr.Button("Generar Copies Personalizados", elem_classes="gr-button-secondary")
|
146 |
custom_output_text = gr.Textbox(label="Copies Personalizados")
|
147 |
|
148 |
generate_custom_button.click(fn=generate_text, inputs=custom_prompt_input, outputs=custom_output_text)
|