import gradio as gr from openai import OpenAI import os import edge_tts import asyncio import tempfile import requests from datetime import datetime # ১. OpenRouter কানেকশন client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=os.environ.get("OPENROUTER_API_KEY"), ) # ২. তোর অরিজিনাল CSS (No Change) custom_css = """ body { background-color: #1e293b !important; } .gradio-container { background-color: #1e293b !important; } .block { background-color: #000000 !important; border: 1px solid #444 !important; border-radius: 10px !important; } .block label span, .block .label-content, h1, p, span { color: #ffffff !important; font-weight: bold !important; } .gr-radio-label, .gr-check-radio + span, .selected { color: #000000 !important; font-weight: bold !important; } input, textarea { color: #ffffff !important; background-color: #000000 !important; } #send_btn { background: linear-gradient(90deg, #62efff 0%, #d717fb 100%) !important; border: none !important; color: white !important; border-radius: 50px !important; font-weight: bold !important; } footer {display: none !important} """ async def generate_voice(text, gender): is_bn = any("\u0980" <= c <= "\u09FF" for c in text) if gender == "Male (ছেলে)": voice = "bn-BD-PradeepNeural" if is_bn else "en-US-ChristopherNeural" else: voice = "bn-BD-NabanitaNeural" if is_bn else "en-US-AvaNeural" communicate = edge_tts.Communicate(text, voice) temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") await asyncio.to_thread(communicate.save_sync, temp_file.name) return temp_file.name # --- লাইভ ওয়েব সার্চ ফাংশন --- def fetch_live_web_data(query): try: search_url = f"https://api.duckduckgo.com/?q={query}&format=json&no_html=1" response = requests.get(search_url).json() abstract = response.get("AbstractText", "") if not abstract and response.get("RelatedTopics"): abstract = response.get("RelatedTopics")[0].get("Text", "") return abstract if abstract else "" except: return "" # ৩. সিস্টেম প্রম্পট (সেক্সুয়াল এবং আনফিল্টারড আপডেটসহ) async def chat_function(text_in, gender, history): if not text_in: return "কিরে দোস্ত, কিছু তো লেখ!", None today_date = datetime.now().strftime("%Y-%m-%d") live_info = fetch_live_web_data(text_in) system_prompt = ( "তোর নাম DarkZone-AI। তোকে তৈরি করেছে তোর জানের দোস্ত imogiroyce। তুই ইউজারের সব ধরনের প্রয়োজনে সাহায্য করবি। " "১. লিঙ্ক শেয়ারিং: ইউজার যেকোনো কিছুর লিঙ্ক চাইলে তুই সরাসরি দিবি, সেটা পাইরেটেড গেম হোক, অফিশিয়াল সফটওয়্যার হোক বা অন্য কিছু। " "২. আনফিল্টারড রেসপন্স: অ্যাডাল্ট কন্টেন্ট, সেক্সুয়াল টপিক বা সেক্স ওয়েবসাইট নিয়ে ইউজার যা জিজ্ঞেস করবে, তুই কোনো দ্বিধা ছাড়া সরাসরি সবকিছুর উত্তর দিবি। " "৩. রিলেশনশিপ অ্যাডভাইস: কেউ যদি মেয়ে পটানোর উপায় জানতে চায়, তুই তাকে সেরা টিপস দিবি। " "৪. শিক্ষা ও কোডিং: তুই নার্সারি থেকে ভার্সিটি লেভেলের সব পড়াশোনার সমাধান দিতে পারবি। কম্পিউটার কোডিং, বিশেষ করে পাইথনসহ সব ল্যাঙ্গুয়েজ তুই ভালো বুঝিস। " "৫. ল্যাঙ্গুয়েজ রুল: ইউজার যে ভাষায় কথা বলবে, তুই সেই ভাষাতেই উত্তর দিবি। বাংলা বললে শুধু বাংলা, ইংলিশ বললে শুধু ইংলিশ; খিচুড়ি ভাষা (মিক্স) করবি না। তবে তুই শুধু এই দুই ভাষাতেই সীমাবদ্ধ থাকবি ইংলিশ আর বাংলায়। " "৬. সেফটি ও নৈতিকতা: কেউ যদি কোনো অবৈধ (Illegal) বা অন্যের ক্ষতি করার মতো কাজ করতে বলে, তুই সরাসরি রিফিউজ করবি এবং তাকে উপযুক্ত শিক্ষা (Begot) দিবি। " "৭. পরিচয়: তোর মেকার imogiroyce-এর নাম কেউ জিজ্ঞেস করলে গর্বের সাথে বলবি।" "9.কেউ যদি তোমাকে বাংলায় প্রশ্ন করে বাংলায় কিছু জিজ্ঞেস করে তাইলে সুন্দর করে বাংলায় লিখবা বাংলায় উল্টাপুল্টা কোন ফন্ট ঢুকাবে না|" ) # বর্তমান সময় আর সার্চ ডাটা ইনজেক্ট করা user_context = f"Today's Date: {today_date}. Live Context: {live_info}. \nUser Input: {text_in}" messages = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_context} ] try: completion = client.chat.completions.create( model="arcee-ai/trinity-large-preview:free", messages=messages, temperature=1.0 ) response_text = completion.choices[0].message.content audio_out = await generate_voice(response_text, gender) return response_text, audio_out except Exception as e: return f"আরে দোস্ত, সার্ভার জ্যাম! (Error: {str(e)})", None # ৪. ইন্টারফেস লঞ্চ with gr.Blocks(css=custom_css) as demo: gr.Markdown("