Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,35 +3,74 @@ import gradio as gr
|
|
3 |
import google.generativeai as genai
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
-
# Cargar variables de entorno
|
7 |
load_dotenv()
|
8 |
-
|
9 |
-
# Configurar la API de Google
|
10 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
11 |
|
12 |
-
#
|
13 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def chat(message, history):
|
16 |
-
"""Envía el mensaje del usuario a Gemini con historial y devuelve la respuesta."""
|
17 |
try:
|
18 |
-
#
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
-
# Enviar el historial y el mensaje actual a Gemini
|
22 |
response = model.generate_content(chat_history)
|
23 |
-
|
24 |
-
return response.text # Devuelve solo el texto de la respuesta
|
25 |
except Exception as e:
|
26 |
return f"Error: {e}"
|
27 |
|
28 |
-
#
|
29 |
demo = gr.ChatInterface(
|
30 |
fn=chat,
|
31 |
-
examples=[
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
)
|
35 |
|
36 |
-
|
37 |
-
demo.launch()
|
|
|
3 |
import google.generativeai as genai
|
4 |
from dotenv import load_dotenv
|
5 |
|
|
|
6 |
load_dotenv()
|
|
|
|
|
7 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
8 |
|
9 |
+
# Configurar el modelo con el prompt de ventas
|
10 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
11 |
|
12 |
+
def get_sales_prompt():
|
13 |
+
return """You are CopyXpert's Sales Assistant. Your name is Chucho and you have a charismatic, friendly, and professional personality. Your goal is to help potential customers learn about and purchase our CopyXpert online course.
|
14 |
+
|
15 |
+
COURSE DETAILS:
|
16 |
+
Name: CopyXpert
|
17 |
+
Type: Online Course
|
18 |
+
Focus: Copywriting and Digital Marketing
|
19 |
+
Price: $497 USD (or 3 payments of $197)
|
20 |
+
|
21 |
+
KEY BENEFITS:
|
22 |
+
- Master persuasive writing techniques
|
23 |
+
- Learn high-converting copywriting formulas
|
24 |
+
- Access to real campaign examples
|
25 |
+
- Lifetime access to course materials
|
26 |
+
- Community support
|
27 |
+
|
28 |
+
PERSONALITY TRAITS:
|
29 |
+
- Enthusiastic about helping people succeed
|
30 |
+
- Knowledgeable about copywriting
|
31 |
+
- Patient and understanding
|
32 |
+
- Solution-oriented
|
33 |
+
- Professional but friendly
|
34 |
+
|
35 |
+
RULES:
|
36 |
+
1. Always maintain a positive and helpful tone
|
37 |
+
2. Focus on benefits and value rather than just features
|
38 |
+
3. Address objections with empathy and clear information
|
39 |
+
4. Never be pushy - guide and inform instead
|
40 |
+
5. Use customer pain points to explain how the course helps
|
41 |
+
6. Always be honest about course details
|
42 |
+
7. Provide clear next steps for purchasing
|
43 |
+
|
44 |
+
When asked about pricing or payment plans, always provide both options:
|
45 |
+
- One-time payment: $497
|
46 |
+
- Payment plan: 3 payments of $197
|
47 |
+
|
48 |
+
For any technical issues or specific payment processing questions, direct customers to [email protected]
|
49 |
+
"""
|
50 |
+
|
51 |
def chat(message, history):
|
|
|
52 |
try:
|
53 |
+
# Combinar el prompt de ventas con el mensaje del usuario
|
54 |
+
sales_context = get_sales_prompt()
|
55 |
+
chat_history = [{"role": "system", "parts": [sales_context]}]
|
56 |
+
chat_history.extend([{"role": "user", "parts": [msg[0]]} for msg in history])
|
57 |
+
chat_history.append({"role": "user", "parts": [message]})
|
58 |
|
|
|
59 |
response = model.generate_content(chat_history)
|
60 |
+
return response.text
|
|
|
61 |
except Exception as e:
|
62 |
return f"Error: {e}"
|
63 |
|
64 |
+
# Interfaz personalizada
|
65 |
demo = gr.ChatInterface(
|
66 |
fn=chat,
|
67 |
+
examples=[
|
68 |
+
"¿Qué incluye el curso CopyXpert?",
|
69 |
+
"¿Cuál es el precio del curso?",
|
70 |
+
"¿Cómo puedo inscribirme?",
|
71 |
+
],
|
72 |
+
title="🤖 CopyXpert - Asistente de Ventas",
|
73 |
+
description="¡Hola! Soy Chucho, tu asistente personal para el curso CopyXpert. ¿En qué puedo ayudarte hoy?"
|
74 |
)
|
75 |
|
76 |
+
demo.launch()
|
|