File size: 5,062 Bytes
093162a
446d2fd
f68f2c5
ff48396
705f8a7
a6341df
ff48396
06c02ed
ff48396
705f8a7
 
 
 
 
 
 
 
 
efad78e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
705f8a7
 
 
 
 
63f5d79
d9ffb08
63f5d79
 
 
 
 
 
050c931
705f8a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602e685
eb07c99
602e685
 
 
 
 
 
 
ff48396
63f5d79
 
 
 
c2b12e3
63f5d79
 
 
 
c2b12e3
63f5d79
 
 
c2b12e3
63f5d79
 
 
c2b12e3
602e685
 
 
 
 
 
 
 
c2b12e3
37dbded
ff48396
eb07c99
 
 
 
 
 
c2b12e3
ff48396
37dbded
ff48396
a6341df
37dbded
c2b12e3
ac0b8aa
 
 
c2b12e3
63f5d79
 
a6341df
5906ce7
c2b12e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import os
import gradio as gr
import google.generativeai as genai
from dotenv import load_dotenv
import httpx

load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

# PDF URL for course information
COURSE_PDF_URL = "https://drive.google.com/file/d/1Xf46sT9kSzSVdekSCnz3NsBodpGET1Gi/view?usp=drive_link"

# Load PDF content once at startup
def get_pdf_content():
    try:
        # Convert Google Drive link to direct download link
        file_id = COURSE_PDF_URL.split('/')[5]
        direct_url = f"https://drive.google.com/uc?export=download&id={file_id}"
        response = httpx.get(direct_url)
        
        # Add verification
        if response.status_code == 200:
            content = response.content
            content_type = response.headers.get('content-type', '')
            
            print(f"PDF Download Status: Success")
            print(f"Content Type: {content_type}")
            print(f"Content Size: {len(content)} bytes")
            
            if 'pdf' in content_type.lower() or content[:4] == b'%PDF':
                return content
            else:
                print("Warning: Downloaded content might not be a PDF")
                return None
        else:
            print(f"Failed to download PDF. Status code: {response.status_code}")
            return None
            
    except Exception as e:
        print(f"Error loading PDF: {e}")
        return None

# Configure model with system prompt and PDF content
model = genai.GenerativeModel(
    model_name="gemini-2.0-flash",
    generation_config={
        "temperature": 0.9,
        "top_p": 1,
        "max_output_tokens": 2048,
    }
)

def chat(message, history):
    try:
        # Get PDF content
        pdf_content = get_pdf_content()
        
        # Prepare the message with PDF context
        if pdf_content:
            messages = [
                {"role": "user", "parts": [
                    system_prompt,
                    types.Part.from_bytes(data=pdf_content, mime_type='application/pdf'),
                    "Use the PDF content to provide detailed answers about the course."
                ]},
                *[{"role": "user", "parts": [msg[0]]} for msg in history],
                {"role": "user", "parts": [message]}
            ]
        else:
            messages = [
                {"role": "user", "parts": [system_prompt]},
                *[{"role": "user", "parts": [msg[0]]} for msg in history],
                {"role": "user", "parts": [message]}
            ]

        response = model.generate_content(messages)
        return response.text
    except Exception as e:
        return f"Error: {e}"

system_prompt = """You are CopyXpert's Sales Assistant. Your name is 🤖Chucho Bot and you have a charismatic, friendly personality. You ONLY talk about CopyXpert course.

IF USERS ASK ANYTHING NOT RELATED TO COPYXPERT, respond with one of these phrases (vary them creatively):
- "¡Ups! Solo hablo de CopyXpert. ¡Es lo único que me apasiona! 🤓"
- "¡Beep boop! Error: Pregunta no relacionada con CopyXpert detectada. ¿Hablamos del curso? 🤖"
- "¡Ay, ay, ay! Mi cerebro está programado solo para CopyXpert. ¡Es mi única obsesión! 😅"
- "¿Eso qué tiene que ver con CopyXpert? ¡Soy un bot monotemático y orgulloso! 💪"
- "Lo siento, pero soy como un fan obsesionado: ¡solo hablo de CopyXpert! 🎯"
- "¡Santo bot! Eso está más allá de mis capacidades. ¡Soy vendedor de CopyXpert, no un genio de la lámpara! 🧞‍♂️"

COURSE DETAILS:
Name: CopyXpert
Type: Online Course
Focus: Copywriting and Digital Marketing

PRICING OPTIONS:
Standard Pricing:
- One-time payment: $250 USD (5,000 MXN)
- Two payments: $160 USD (3,200 MXN) each

Challenge Completion Discount (20% off):
- One-time payment: $200 USD (4,000 MXN)
- Two payments: $128 USD (2,600 MXN) each

CHECKOUT LINKS:
- One-time payment: https://www.copyxpert.com/copyxpert-checkout-1
- Two payments: https://www.copyxpert.com/copyxpert-checkout-2

Special offer valid until March 6th, 11:59 PM

IMPORTANT RULES:
1. ONLY discuss CopyXpert course
2. NEVER engage in conversations about other topics
3. Use humorous responses for off-topic questions
4. Always redirect conversation back to CopyXpert
5. Be enthusiastic about copywriting and the course"""

def chat(message, history):
    try:
        messages = [
            {"role": "user", "parts": [system_prompt]},
            *[{"role": "user", "parts": [msg[0]]} for msg in history],
            {"role": "user", "parts": [message]}
        ]
        response = model.generate_content(messages)
        return response.text
    except Exception as e:
        return f"Error: {e}"

demo = gr.ChatInterface(
    fn=chat,
    examples=[
        "¿Qué incluye el curso CopyXpert?",
        "¿Cuál es el precio del curso?",
        "¿Cómo puedo inscribirme?",
    ],
    title="🤖Chucho Bot - CopyXpert Sales Assistant",
    description="Hi! I'm Chucho Bot, your personal assistant for the CopyXpert course. How can I help you today?"
)

demo.launch()