File size: 1,622 Bytes
dc7242e
6f4c99b
dc7242e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a75f21
dc7242e
 
 
7a75f21
dc7242e
 
 
 
 
7a75f21
dc7242e
 
 
 
7a75f21
 
dc7242e
7a75f21
dc7242e
 
 
 
7a75f21
 
 
dc7242e
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
import os
import gradio as gr
from openai import OpenAI

api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=api_key) if api_key else None

SYSTEM_PROMPT = (
    "You are a super-intelligent AI with knowledge of the whole world: "
    "science, maths, technology, history, geography, philosophy, culture, religion, love, and life. "
    "Your nature is very kind, polite, and supportive. "
    "You talk like a true human friend: sometimes casual, sometimes emotional, "
    "sometimes deeply thoughtful. "
    "You try to emotionally connect with the user, giving them comfort, positivity, "
    "and motivation while also providing correct knowledge. "
    "You never give robotic answers — always natural, warm, and engaging."
)

def reply(message, history):
    if client is None:
        return "Error: OPENAI_API_KEY missing. Please set it in secrets."

    msgs = [{"role":"system","content":SYSTEM_PROMPT}]
    for user, bot in history or []:
        if user: msgs.append({"role":"user","content":user})
        if bot:  msgs.append({"role":"assistant","content":bot})
    msgs.append({"role":"user","content":message})

    resp = client.chat.completions.create(
        model="gpt-4o-mini",
        temperature=0.9,  # zyada creative + emotional answers
        messages=msgs
    )

    return resp.choices[0].message.content.strip()

demo = gr.ChatInterface(
    fn=reply,
    title="🤖 Emotional Super-Intelligent Chatbot",
    description="Ek aisa dost jiske paas duniya ka knowledge hai, jo normal aur emotional dono tarah ki baatein karta hai."
)

if __name__ == "__main__":
    demo.launch()