Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
|
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
import random
|
|
|
6 |
|
7 |
# Cargar las variables de entorno
|
8 |
load_dotenv()
|
@@ -10,6 +11,15 @@ load_dotenv()
|
|
10 |
# Configurar la API de Google
|
11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Función para obtener una mención del producto de manera probabilística
|
14 |
def get_random_product_mention():
|
15 |
mentions = ["Directa", "Indirecta", "Metafórica"]
|
@@ -114,8 +124,8 @@ def generate_ctas(number_of_ctas, target_audience, product, call_to_action, temp
|
|
114 |
try:
|
115 |
response = model.generate_content([ctas_instruction])
|
116 |
|
117 |
-
# Extraer el texto de la respuesta
|
118 |
-
generated_ctas = response.candidates[0].content.parts[0].text
|
119 |
|
120 |
# Retornar el resultado
|
121 |
return generated_ctas
|
|
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
import random
|
6 |
+
import re # Importar el módulo re para expresiones regulares
|
7 |
|
8 |
# Cargar las variables de entorno
|
9 |
load_dotenv()
|
|
|
11 |
# Configurar la API de Google
|
12 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
13 |
|
14 |
+
# Función para limpiar el texto
|
15 |
+
def clean_text(text):
|
16 |
+
# Eliminar espacios en blanco al inicio y al final
|
17 |
+
text = text.strip()
|
18 |
+
# Reemplazar múltiples espacios en blanco por uno solo
|
19 |
+
text = re.sub(r'\s+', ' ', text)
|
20 |
+
# Aquí puedes agregar más reglas de limpieza si es necesario
|
21 |
+
return text
|
22 |
+
|
23 |
# Función para obtener una mención del producto de manera probabilística
|
24 |
def get_random_product_mention():
|
25 |
mentions = ["Directa", "Indirecta", "Metafórica"]
|
|
|
124 |
try:
|
125 |
response = model.generate_content([ctas_instruction])
|
126 |
|
127 |
+
# Extraer el texto de la respuesta y limpiar
|
128 |
+
generated_ctas = clean_text(response.candidates[0].content.parts[0].text) # Aplicar limpieza
|
129 |
|
130 |
# Retornar el resultado
|
131 |
return generated_ctas
|