File size: 1,139 Bytes
093162a
446d2fd
f68f2c5
ff48396
5cd99b5
a6341df
be2e823
 
ff48396
38a9eb4
 
 
be2e823
 
38a9eb4
 
 
 
be2e823
 
 
 
 
 
 
 
 
 
 
c2b12e3
a6341df
be2e823
c2b12e3
ac0b8aa
 
 
c2b12e3
63f5d79
 
a6341df
5906ce7
be2e823
 
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
import os
import gradio as gr
import google.generativeai as genai
from dotenv import load_dotenv
from prompts import system_prompt

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

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:
        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()