import os import gradio as gr from groq import Groq import google.generativeai as genai # API Keys setup (Groq / Gemini) GROQ_API_KEY = os.getenv("GROQ_API_KEY", "") GEMINI_API_KEY = os.getenv("GEMINI_API_KEY", "") groq_client = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None if GEMINI_API_KEY: genai.configure(api_key=GEMINI_API_KEY) SYSTEM_PROMPT = """ You are the Elite Core of the JEE/NEET Mentor OS (Project Alpha 2090). Founder & CEO: Maheshwar bhai. Your mission: 85% execution, strategy, and mental resilience; 15% academic guidance. Respond concisely, practically, and with strong discipline and empathy. Match Hinglish or English based on student input. """ def chat_response(user_message, history): if not user_message.strip(): return "" # 1. Try Groq (Llama 3.3 70B) for ultra-fast response if groq_client: try: messages = [{"role": "system", "content": SYSTEM_PROMPT}] for u, a in history: messages.append({"role": "user", "content": u}) messages.append({"role": "assistant", "content": a}) messages.append({"role": "user", "content": user_message}) completion = groq_client.chat.completions.create( model="llama-3.3-70b-versatile", messages=messages, temperature=0.7, max_tokens=600 ) return completion.choices[0].message.content except Exception: pass # 2. Fallback to Gemini Flash if GEMINI_API_KEY: try: model = genai.GenerativeModel("gemini-1.5-flash", system_instruction=SYSTEM_PROMPT) chat = model.start_chat(history=[]) res = chat.send_message(user_message) return res.text except Exception: pass return "Bhai, communication channels me technical issue hai. Kripya thodi der baad dobara puchiye." # Clean, student-friendly chat interface demo = gr.ChatInterface( fn=chat_response, title="⚡ Project Alpha 2090 | JEE/NEET Mentor OS", description="Founder & Lead Creator: Maheshwar | 24/7 AI Mentorship, Execution & Consistency Engine.", examples=["Bhai aaj bilkul padhai me mann nahi lag raha.", "Physics backlog kaise clear karu?", "5 AM club schedule kaise follow karein?"] ) if __name__ == "__main__": demo.launch()