JeCabrera commited on
Commit
62e78e9
verified
1 Parent(s): d4d2e2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -12,18 +12,19 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
12
 
13
  # Funci贸n para obtener una cantidad de bullets
14
  def get_gemini_response_bullets(target_audience, product, num_bullets, temperature):
15
- model_choice = "gemini-1.5-flash" # Modelo por defecto
16
 
17
  # Configuraci贸n del modelo generativo y las instrucciones del sistema
18
- model = genai.GenerativeModel(
19
- model_name=model_choice,
20
- generation_config={
21
  "temperature": temperature,
22
  "top_p": 0.9, # Aumentar para permitir una mayor diversidad en las opciones generadas
23
  "top_k": 90,
24
  "max_output_tokens": 2048,
25
  "response_mime_type": "text/plain",
26
  },
 
 
 
 
27
  system_instruction=(
28
  f"Imagina que est谩s charlando con un amigo que est谩 buscando {product}. "
29
  f"Genera {num_bullets} bullets que suenen naturales y amigables, como si estuvieras cont谩ndole por qu茅 deber铆a interesarse. "
@@ -35,27 +36,23 @@ def get_gemini_response_bullets(target_audience, product, num_bullets, temperatu
35
  )
36
  )
37
 
38
- # Crear la instrucci贸n para generar bullets
39
- chat_session = model.start_chat(
40
- history=[
41
- {
42
- "role": "user",
43
- "parts": [
44
- f"Quiero que escribas {num_bullets} bullets que transmitan los beneficios de {product} de una manera que atraiga a {target_audience}. "
45
- f"Conecta los problemas y deseos de {target_audience} de forma conversacional, no robotico, ni utilices ':', con un estilo amigable y divertido. "
46
- f"Por favor, genera bullets creativos que hagan que {target_audience} se sienta emocionado por {product}."
47
- ],
48
- },
49
- ]
50
- )
51
-
52
- # Crear un mensaje para el modelo que incluye los bullets generados
53
- response = model.generate_content(chat_session.history) # Aqu铆 usamos el historial del chat
54
 
55
- if response and response.parts:
56
- return response.parts[0].text
57
- else:
58
- raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
 
 
 
 
 
 
 
59
 
60
  # Inicializar la aplicaci贸n Streamlit
61
  st.set_page_config(page_title="Generador de Bullets", layout="wide")
 
12
 
13
  # Funci贸n para obtener una cantidad de bullets
14
  def get_gemini_response_bullets(target_audience, product, num_bullets, temperature):
 
15
 
16
  # Configuraci贸n del modelo generativo y las instrucciones del sistema
17
+ generation_config= {
 
 
18
  "temperature": temperature,
19
  "top_p": 0.9, # Aumentar para permitir una mayor diversidad en las opciones generadas
20
  "top_k": 90,
21
  "max_output_tokens": 2048,
22
  "response_mime_type": "text/plain",
23
  },
24
+ # Configuraci贸n del modelo generativo y las instrucciones del sistema
25
+ model = genai.GenerativeModel(
26
+ model_name="gemini-1.5-flash", # Nombre del modelo que estamos utilizando
27
+ generation_config=generation_config, # Configuraci贸n de generaci贸n
28
  system_instruction=(
29
  f"Imagina que est谩s charlando con un amigo que est谩 buscando {product}. "
30
  f"Genera {num_bullets} bullets que suenen naturales y amigables, como si estuvieras cont谩ndole por qu茅 deber铆a interesarse. "
 
36
  )
37
  )
38
 
39
+ bullets_instruction = (
40
+ f"Quiero que escribas {num_bullets} bullets que transmitan los beneficios de {product} de una manera que atraiga a {target_audience}. "
41
+ f"Conecta los problemas y deseos de {target_audience} de forma conversacional, no rob贸tico, ni utilices ':', con un estilo amigable y divertido. "
42
+ f"Por favor, genera bullets creativos que hagan que {target_audience} se sienta emocionado por {product}."
43
+ )
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ # Generar el resultado utilizando el modelo con la instrucci贸n espec铆fica
46
+ try:
47
+ response = model.generate_content([bullets_instruction])
48
+
49
+ # Extraer el texto de la respuesta
50
+ generated_bullets = response.candidates[0].content.parts[0].text.strip()
51
+
52
+ # Retornar el resultado
53
+ return generated_bullets
54
+ except Exception as e:
55
+ raise ValueError(f"Error al generar los bullets: {str(e)}")
56
 
57
  # Inicializar la aplicaci贸n Streamlit
58
  st.set_page_config(page_title="Generador de Bullets", layout="wide")