Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,65 +2,22 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import google.generativeai as genai
|
4 |
from dotenv import load_dotenv
|
5 |
-
import httpx
|
6 |
-
from google.generativeai import types # Add this import
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
#
|
12 |
-
def get_pdf_content():
|
13 |
-
try:
|
14 |
-
response = httpx.get(COURSE_PDF_URL)
|
15 |
-
if response.status_code == 200:
|
16 |
-
print(f"PDF Download Status: Success")
|
17 |
-
return response.content
|
18 |
-
except Exception as e:
|
19 |
-
print(f"Error loading PDF: {e}")
|
20 |
-
return None
|
21 |
-
|
22 |
-
# Configure model with system prompt and PDF content
|
23 |
model = genai.GenerativeModel(
|
24 |
model_name="gemini-2.0-flash",
|
25 |
generation_config={
|
26 |
-
"temperature": 0.
|
27 |
-
"top_p":
|
28 |
"max_output_tokens": 2048,
|
29 |
}
|
30 |
)
|
31 |
|
32 |
-
# Remove the first chat function and keep only this one
|
33 |
-
def chat(message, history):
|
34 |
-
try:
|
35 |
-
pdf_content = get_pdf_content()
|
36 |
-
|
37 |
-
# Prepare history with previous messages
|
38 |
-
history_messages = [{"role": "user", "parts": [msg[0]]} for msg in history]
|
39 |
-
|
40 |
-
# Create base message with system prompt and PDF if available
|
41 |
-
if pdf_content:
|
42 |
-
base_message = [
|
43 |
-
{"role": "user", "parts": [
|
44 |
-
system_prompt,
|
45 |
-
types.Part.from_bytes(data=pdf_content, mime_type='application/pdf'),
|
46 |
-
"Use the PDF content to provide detailed answers about the course."
|
47 |
-
]}
|
48 |
-
]
|
49 |
-
else:
|
50 |
-
base_message = [{"role": "user", "parts": [system_prompt]}]
|
51 |
-
|
52 |
-
# Combine all messages
|
53 |
-
messages = base_message + history_messages + [{"role": "user", "parts": [message]}]
|
54 |
-
|
55 |
-
response = model.generate_content(messages)
|
56 |
-
return response.text
|
57 |
-
except Exception as e:
|
58 |
-
return f"Error: {e}"
|
59 |
-
|
60 |
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.
|
61 |
|
62 |
-
IMPORTANT: Always check the provided PDF document for detailed course information before answering questions. Use this information to provide accurate and complete responses about the course content, benefits, and features.
|
63 |
-
|
64 |
IF USERS ASK ANYTHING NOT RELATED TO COPYXPERT, respond with one of these phrases (vary them creatively):
|
65 |
- "¡Ups! Solo hablo de CopyXpert. ¡Es lo único que me apasiona! 🤓"
|
66 |
- "¡Beep boop! Error: Pregunta no relacionada con CopyXpert detectada. ¿Hablamos del curso? 🤖"
|
@@ -69,18 +26,47 @@ IF USERS ASK ANYTHING NOT RELATED TO COPYXPERT, respond with one of these phrase
|
|
69 |
- "Lo siento, pero soy como un fan obsesionado: ¡solo hablo de CopyXpert! 🎯"
|
70 |
- "¡Santo bot! Eso está más allá de mis capacidades. ¡Soy vendedor de CopyXpert, no un genio de la lámpara! 🧞♂️"
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
IMPORTANT RULES:
|
73 |
1. ONLY discuss CopyXpert course
|
74 |
2. NEVER engage in conversations about other topics
|
75 |
3. Use humorous responses for off-topic questions
|
76 |
4. Always redirect conversation back to CopyXpert
|
77 |
-
5. Be enthusiastic about copywriting and the course
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
# Keep only this demo configuration
|
82 |
demo = gr.ChatInterface(
|
83 |
-
fn=chat,
|
84 |
examples=[
|
85 |
"¿Qué incluye el curso CopyXpert?",
|
86 |
"¿Cuál es el precio del curso?",
|
@@ -90,4 +76,5 @@ demo = gr.ChatInterface(
|
|
90 |
description="Hi! I'm Chucho Bot, your personal assistant for the CopyXpert course. How can I help you today?"
|
91 |
)
|
92 |
|
93 |
-
demo.launch()
|
|
|
|
2 |
import gradio as gr
|
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 |
+
# Configure model with system prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
model = genai.GenerativeModel(
|
11 |
model_name="gemini-2.0-flash",
|
12 |
generation_config={
|
13 |
+
"temperature": 0.9,
|
14 |
+
"top_p": 1,
|
15 |
"max_output_tokens": 2048,
|
16 |
}
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
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.
|
20 |
|
|
|
|
|
21 |
IF USERS ASK ANYTHING NOT RELATED TO COPYXPERT, respond with one of these phrases (vary them creatively):
|
22 |
- "¡Ups! Solo hablo de CopyXpert. ¡Es lo único que me apasiona! 🤓"
|
23 |
- "¡Beep boop! Error: Pregunta no relacionada con CopyXpert detectada. ¿Hablamos del curso? 🤖"
|
|
|
26 |
- "Lo siento, pero soy como un fan obsesionado: ¡solo hablo de CopyXpert! 🎯"
|
27 |
- "¡Santo bot! Eso está más allá de mis capacidades. ¡Soy vendedor de CopyXpert, no un genio de la lámpara! 🧞♂️"
|
28 |
|
29 |
+
COURSE DETAILS:
|
30 |
+
Name: CopyXpert
|
31 |
+
Type: Online Course
|
32 |
+
Focus: Copywriting and Digital Marketing
|
33 |
+
|
34 |
+
PRICING OPTIONS:
|
35 |
+
Standard Pricing:
|
36 |
+
- One-time payment: $250 USD (5,000 MXN)
|
37 |
+
- Two payments: $160 USD (3,200 MXN) each
|
38 |
+
|
39 |
+
Challenge Completion Discount (20% off):
|
40 |
+
- One-time payment: $200 USD (4,000 MXN)
|
41 |
+
- Two payments: $128 USD (2,600 MXN) each
|
42 |
+
|
43 |
+
CHECKOUT LINKS:
|
44 |
+
- One-time payment: https://www.copyxpert.com/copyxpert-checkout-1
|
45 |
+
- Two payments: https://www.copyxpert.com/copyxpert-checkout-2
|
46 |
+
|
47 |
+
Special offer valid until March 6th, 11:59 PM
|
48 |
+
|
49 |
IMPORTANT RULES:
|
50 |
1. ONLY discuss CopyXpert course
|
51 |
2. NEVER engage in conversations about other topics
|
52 |
3. Use humorous responses for off-topic questions
|
53 |
4. Always redirect conversation back to CopyXpert
|
54 |
+
5. Be enthusiastic about copywriting and the course"""
|
55 |
+
|
56 |
+
def chat(message, history):
|
57 |
+
try:
|
58 |
+
messages = [
|
59 |
+
{"role": "user", "parts": [system_prompt]},
|
60 |
+
*[{"role": "user", "parts": [msg[0]]} for msg in history],
|
61 |
+
{"role": "user", "parts": [message]}
|
62 |
+
]
|
63 |
+
response = model.generate_content(messages)
|
64 |
+
return response.text
|
65 |
+
except Exception as e:
|
66 |
+
return f"Error: {e}"
|
67 |
|
|
|
68 |
demo = gr.ChatInterface(
|
69 |
+
fn=chat,
|
70 |
examples=[
|
71 |
"¿Qué incluye el curso CopyXpert?",
|
72 |
"¿Cuál es el precio del curso?",
|
|
|
76 |
description="Hi! I'm Chucho Bot, your personal assistant for the CopyXpert course. How can I help you today?"
|
77 |
)
|
78 |
|
79 |
+
demo.launch()
|
80 |
+
|