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