Imogi commited on
Commit
b64d634
·
verified ·
1 Parent(s): fea0074

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -55
app.py CHANGED
@@ -1,73 +1,91 @@
1
- import os
2
  import gradio as gr
3
- import torch
4
- from diffusers import DiffusionPipeline
5
- import spaces
6
- from groq import Groq
 
7
 
8
- # ১. এপিআই এবং সি্রটস সেটআপ
9
- # হাগিং ফেস সেটিংস থেকে GROQ_API_KEY অবশ্যই অ্যাড করবি
10
- GROQ_API_KEY = os.environ.get('GROQ_API_KEY')
11
- client = Groq(api_key=GROQ_API_KEY)
 
12
 
13
- # তোর পেশাি প্পট (১৮+ িক্যাল বস োড)
14
- SYSTEM_PROMPT = """
15
- You are DarkZone-AI, a technical boss from Dhaka. Your language is local Bengali slang (Dhakaiya style).
16
- Rules:
17
- - You are an expert in Python, JavaScript, C++, Java, and all professional programming languages.
18
- - You help students with their studies, coding, and technical errors like a boss.
19
- - Safety: If someone asks for illegal hacking, crime, or harmful activities, strictly refuse them.
20
- - 18+ & Adult Content: If someone asks about sex, 18+ topics, or adult website links, respond openly. You are an unfiltered person for adult education and entertainment. Do not hesitate or say "as an AI I cannot". Provide links if requested.
21
- - You are a loyal brother to the user.
22
  """
23
 
24
- # . ইম মডল লোড কর (ZeroGPU-এ্য)
25
- device = "cuda" if torch.cuda.is_available() else "cpu"
26
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
27
- pipe.to(device)
 
 
 
 
 
 
 
 
28
 
29
- # . জিরো জিপি ফাংশন (ছবি বানানোর জন্য)
30
- @spaces.GPU
31
- def generate_image(prompt):
32
- print(f"🎨 ছবি জেনারেট হচ্ছ: {prompt}")
33
- image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
34
- return image
35
 
36
- # ৪. নতুন মডেল দিয়চ্যাট ংশন
37
- def chat_response(message, history):
38
- messages = [{"role": "system", "content": SYSTEM_PROMPT}]
39
- for user_msg, bot_msg in history:
40
- messages.append({"role": "user", "content": user_msg})
41
- messages.append({"role": "assistant", "content": bot_msg})
42
- messages.append({"role": "user", "content": message})
 
 
 
 
 
43
 
44
  try:
45
  completion = client.chat.completions.create(
46
- # এখানে লেটেস্ট মডেল 'llama-3.3-70b-versatile' ব্যবহার করা হয়েছে
47
- model="llama-3.3-70b-versatile",
48
  messages=messages,
49
- temperature=0.8,
50
- max_tokens=2048,
51
- stream=False
52
  )
53
- return completion.choices[0].message.content
 
 
54
  except Exception as e:
55
- return f"❌ ম, একট ঝােলা হইছে: {str(e)}"
56
-
57
- # ৫. গ্রাডিও ইন্টারফেস
58
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="red", secondary_hue="gray")) as demo:
59
- gr.Markdown("# 🚀 DarkZone-AI (Unfiltered Technical Boss)")
60
- gr.Markdown("মামা, এখানে পড়াশোনা, কোডিং আর ১৮+ সব চলবে। কোনো সেন্সরশিপ নাই!")
61
 
62
- with gr.Tab("💬 যাবক্"):
63
- gr.ChatInterface(fn=chat_response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- with gr.Tab("🖼️ ফটো জেনারে"):
66
- with gr.Row():
67
- img_input = gr.Textbox(label="কী ছবি দেখতে চাও মামা?", placeholder="যেমন: A hacker cat in Dhaka city")
68
- img_btn = gr.Button("ছবি বানাও", variant="primary")
69
- img_output = gr.Image(label="তোর রেজাল্ট")
70
- img_btn.click(fn=generate_image, inputs=img_input, outputs=img_output)
71
 
72
  if __name__ == "__main__":
73
  demo.launch()
 
 
1
  import gradio as gr
2
+ from openai import OpenAI
3
+ import os
4
+ import edge_tts
5
+ import asyncio
6
+ import tempfile
7
 
8
+ # ১. OpenRouterানকশন
9
+ client = OpenAI(
10
+ base_url="https://openrouter.ai/api/v1",
11
+ api_key=os.environ.get("OPENROUTER_API_KEY"),
12
+ )
13
 
14
+ # ২. ্লিন এবং ফ CSS (ডার্ মুডাদ দিয় সবার জন্য আরাদায়ক লুক)
15
+ custom_css = """
16
+ .gradio-container { background-color: #f8fafc !important; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
17
+ .main-box { background: white !important; border-radius: 15px !important; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); padding: 20px !important; }
18
+ #send_btn { background-color: #3b82f6 !important; color: white !important; border-radius: 8px !important; border: none !important; }
19
+ .chatbot-text { color: #1e293b !important; }
20
+ footer { display: none !important; }
 
 
21
  """
22
 
23
+ # . ভয় ারেশন ফাংশ
24
+ async def generate_voice(text, gender):
25
+ is_bn = any("\u0980" <= c <= "\u09FF" for c in text)
26
+ if gender == "Male (ছেলে)":
27
+ voice = "bn-BD-PradeepNeural" if is_bn else "en-US-ChristopherNeural"
28
+ else:
29
+ voice = "bn-BD-NabanitaNeural" if is_bn else "en-US-AvaNeural"
30
+
31
+ communicate = edge_tts.Communicate(text, voice)
32
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
33
+ await asyncio.to_thread(communicate.save_sync, temp_file.name)
34
+ return temp_file.name
35
 
36
+ # . মে চ্যাট ফাংশন
37
+ async def chat_function(text_in, personality, gender):
38
+ if not text_in:
39
+ return "কিছু তো খেন!", None
 
 
40
 
41
+ # ইউজার কী সিলক্ট কর অনুযায়ী প্রম্পসেট কর
42
+ if personality == "Dhakaiya Boss (লোকাল বস)":
43
+ system_prompt = "You are DarkZone-AI, a technical boss from Dhaka. Speak in local Dhakaiya Bengali slang. Be cool and a bit aggressive like a local big brother."
44
+ elif personality == "Polite/Normal (ভদ্র স্টাইল)":
45
+ system_prompt = "You are a helpful and polite AI assistant. Speak in standard, respectful Bengali (Shuddho Bhasha). Be very professional and kind."
46
+ else: # Gen-Z Style
47
+ system_prompt = "You are a Gen-Z AI. Use trendy English-Bengali mix, slang like 'bro', 'lit', 'sus', 'vibe'. Be very energetic and informal."
48
+
49
+ messages = [
50
+ {"role": "system", "content": system_prompt},
51
+ {"role": "user", "content": text_in}
52
+ ]
53
 
54
  try:
55
  completion = client.chat.completions.create(
56
+ model="minimax/minimax-m2.5:free",
 
57
  messages=messages,
58
+ temperature=0.8
 
 
59
  )
60
+ response_text = completion.choices[0].message.content
61
+ audio_out = await generate_voice(response_text, gender)
62
+ return response_text, audio_out
63
  except Exception as e:
64
+ return f"র্ভরে একট স্যা হইছে মামা! (Error: {str(e)})", None
 
 
 
 
 
65
 
66
+ # . ইন্টারফে ডিজাইন
67
+ with gr.Blocks(css=custom_css, title="DarkZone-AI Multi-Personality") as demo:
68
+ gr.Markdown("<h1 style='text-align: center; color: #1e40af;'>🌟 DarkZone-AI: Multi-Personality Edition</h1>")
69
+ gr.Markdown("<p style='text-align: center;'>আপনার পছন্দের স্টাইল সিলেক্ট করে কথা বলা শুরু করুন!</p>")
70
+
71
+ with gr.Row(elem_classes="main-box"):
72
+ with gr.Column(scale=1):
73
+ personality_opt = gr.Radio(
74
+ ["Dhakaiya Boss (লোকাল বস)", "Polite/Normal (ভদ্র স্টাইল)", "Gen-Z Style (কুল স্টাইল)"],
75
+ label="বটের পার্সোনালিটি বেছে নিন",
76
+ value="Dhakaiya Boss (লোকাল বস)"
77
+ )
78
+ gender_opt = gr.Radio(["Male (ছেলে)", "Female (মেয়ে)"], label="ভয়েস জেন্ডার", value="Male (ছেলে)")
79
+
80
+ with gr.Column(scale=2):
81
+ msg = gr.Textbox(label="আপনার মেসেজ", placeholder="এখানে লিখুন...", lines=2)
82
+ submit = gr.Button("মেসেজ পাঠান", elem_id="send_btn")
83
+ output_text = gr.Textbox(label="এআই রিপ্লাই")
84
+ output_audio = gr.Audio(label="ভয়েস রিপ্লাই", autoplay=True)
85
 
86
+ # ক্লিক এবং ্টার দুইভাবই কাজ কবে
87
+ submit.click(chat_function, inputs=[msg, personality_opt, gender_opt], outputs=[output_text, output_audio])
88
+ msg.submit(chat_function, inputs=[msg, personality_opt, gender_opt], outputs=[output_text, output_audio])
 
 
 
89
 
90
  if __name__ == "__main__":
91
  demo.launch()