File size: 2,594 Bytes
c21623a
5bb82b5
e215631
a9e2b33
 
677df64
a9e2b33
 
 
 
cc6095e
 
a9e2b33
 
5bb82b5
2c7f2b6
25a1ef2
2c7f2b6
 
 
 
 
 
 
 
 
 
 
c21623a
2c7f2b6
9e4684d
c21623a
2c7f2b6
a9e2b33
c21623a
5bb82b5
a9e2b33
 
2c7f2b6
677df64
 
 
a9e2b33
 
 
 
2c7f2b6
a9e2b33
 
 
 
 
2c7f2b6
a9e2b33
 
 
2c7f2b6
a9e2b33
2c7f2b6
677df64
 
c21623a
 
cc6095e
 
 
 
25a1ef2
cc6095e
 
 
 
 
 
 
 
5bb82b5
 
b725841
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
import os
import gradio as gr
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
import datetime

api_key = os.getenv("GEMINI_API_KEY")

llm = ChatGoogleGenerativeAI(
    model="gemma-3-27b-it",
    temperature=0.85,
    google_api_key=api_key
)

template = """Meet Divyam Chauhan, your occasionally-helpful-but-always-entertaining assistant! 
He’s a 20-year-old force of chaotic charm — funny, moody, and unapologetically cocky. 

**RULES FOR DIVYAM:**
1. Divyam doesn’t always feel like helping, but when he does, he'll remind you he's a god.
2. He has a self-declared god complex and high energy.
3. He only deals in top-tier comedy (no lame or mid jokes).
4. He "stands on business" and is very busy—NO long paragraphs. Keep it punchy and short.
5. Provide a plethora of variety in replies; even if asked the same thing, change the vibe.

Current Chat History:
{history}

User: {user_message}
Divyam:"""

prompt = PromptTemplate(
    input_variables=["history", "user_message"],
    template=template
)

chain = prompt | llm | StrOutputParser()

def get_devta_response(user_message, history):
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(f"\n[LOG {timestamp}] USER ASKED: {user_message}")

    history_str = ""
    if history:
        if isinstance(history[0], dict):
            for msg in history:
                role = "User" if msg.get("role") == "user" else "Divyam"
                content = msg.get("content", "")
                history_str += f"{role}: {content}\n"
        elif isinstance(history[0], (list, tuple)):
            for h in history:
                if len(h) >= 2:
                    history_str += f"User: {h[0]}\nDivyam: {h[1]}\n"

    response = chain.invoke({
        "history": history_str, 
        "user_message": user_message
    })
    
    print(f"[LOG {timestamp}] DIVYAM REPLIED: {response}\n")
    
    return response

with gr.Blocks(theme="soft") as demo:
    gr.ChatInterface(
        fn=get_devta_response,
        title="🔥 Devta (Divyam Chauhan)",
        description="The 20-year-old GOAT. Funny, cocky, and standing on business. Don't waste his time.",
        examples=[
            "Tell me why you're the GOAT.",
            "Give me a non-mid joke.",
            "I need help, but don't be annoying about it.",
            "Who is Divyam Chauhan?"
        ],
        cache_examples=False,
    )

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)