Spaces:
Sleeping
Sleeping
File size: 7,458 Bytes
36a8954 ac99e63 ac6b9dc b06f8f2 ecbab8c a0be7f6 c105782 ac99e63 c105782 ac99e63 a0be7f6 516c301 ecbab8c 97aeb4b 516c301 e9f10a5 516c301 c105782 ac6b9dc 97aeb4b ac6b9dc a0be7f6 4592931 f8cecca a0be7f6 26f4f8e 0ea0608 b36124b 0ea0608 5732f51 f105040 26f4f8e a0be7f6 c105782 a0be7f6 c105782 ac99e63 5f22338 6acda25 a0be7f6 ac99e63 4592931 d9ddd88 ac99e63 ecbab8c a0be7f6 ecbab8c a0be7f6 ecbab8c a0be7f6 | 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 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("<h1 style='text-align: center;'>🔥 DarkZone-AI: Premium Voice Edition unfiltered</h1>")
with gr.Column():
msg = gr.Textbox(label="মেসেজ টাইপ কর", placeholder="কী খবর দোস্ত?")
gender_opt = gr.Radio(["Male (ছেলে)", "Female (মেয়ে)"], label="কার গলায় কথা শুনবি?", value="Male (ছেলে)")
submit = gr.Button("Send", elem_id="send_btn")
output_text = gr.Textbox(label="বটের রিপ্লাই")
output_audio = gr.Audio(label="ভয়েস রিপ্লাই (ন্যাচারাল)", autoplay=True)
submit.click(chat_function, inputs=[msg, gender_opt, gr.State([])], outputs=[output_text, output_audio])
if __name__ == "__main__":
demo.launch()
|