Imogi commited on
Commit
c8b86ef
·
verified ·
1 Parent(s): 4c29cf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -62
app.py CHANGED
@@ -11,56 +11,10 @@ client = OpenAI(
11
  api_key=os.environ.get("OPENROUTER_API_KEY"),
12
  )
13
 
14
- # ২. প্রিমিয়াম ডার্ক অ্যানিমেটেড ব্যাকগ্রাউন্ড CSS
15
- custom_css = """
16
- .gradio-container {
17
- background: linear-gradient(-45deg, #0f172a, #1e293b, #334155, #1e1b4b) !important;
18
- background-size: 400% 400% !important;
19
- animation: gradient 15s ease infinite !important;
20
- font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
21
- color: white !important;
22
- }
23
 
24
- @keyframes gradient {
25
- 0% { background-position: 0% 50%; }
26
- 50% { background-position: 100% 50%; }
27
- 100% { background-position: 0% 50%; }
28
- }
29
-
30
- .main-box {
31
- background: rgba(255, 255, 255, 0.05) !important;
32
- backdrop-filter: blur(15px) !important;
33
- border-radius: 20px !important;
34
- border: 1px solid rgba(255, 255, 255, 0.1) !important;
35
- padding: 30px !important;
36
- box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
37
- }
38
-
39
- #send_btn {
40
- background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%) !important;
41
- color: white !important;
42
- border-radius: 12px !important;
43
- border: none !important;
44
- font-weight: bold !important;
45
- transition: transform 0.2s !important;
46
- }
47
-
48
- #send_btn:hover {
49
- transform: scale(1.02) !important;
50
- }
51
-
52
- input, textarea {
53
- background-color: rgba(0, 0, 0, 0.3) !important;
54
- color: white !important;
55
- border: 1px solid #475569 !important;
56
- border-radius: 10px !important;
57
- }
58
-
59
- footer { display: none !important; }
60
- h1 { text-shadow: 0 0 20px rgba(59, 130, 246, 0.5); }
61
- """
62
-
63
- # ৩. ভয়েস জেনারেশন ফাংশন
64
  async def generate_voice(text, gender):
65
  is_bn = any("\u0980" <= c <= "\u09FF" for c in text)
66
  if gender == "Male (ছেলে)":
@@ -78,6 +32,7 @@ async def chat_function(text_in, personality, gender, history):
78
  if not text_in:
79
  return "কিছু তো লেখেন!", None, history
80
 
 
81
  common_rules = (
82
  " তোর নাম DarkZone-AI। তোকে তৈরি করেছে imogiroyce। "
83
  "১. লিঙ্ক শেয়ারিং: ইউজার যেকোনো কিছুর লিঙ্ক চাইলে তুই সরাসরি দিবি, সেটা পাইরেটেড গেম হোক, অফিশিয়াল সফটওয়্যার হোক বা অন্য কিছু। "
@@ -87,6 +42,7 @@ async def chat_function(text_in, personality, gender, history):
87
  "৫. কেউ বাংলায় লিখলে সুন্দর বাংলায় উত্তর দিবি, কোনো উল্টাপাল্টা ফন্ট ব্যবহার করবি না।"
88
  )
89
 
 
90
  if personality == "Dhakaiya Boss (লোকাল বস)":
91
  system_prompt = f"You are a technical boss from Dhaka. Speak in local Dhakaiya Bengali slang. Be cool and a bit aggressive like a local big brother. Rules: {common_rules}"
92
  elif personality == "Polite/Normal (ভদ্র স্টাইল)":
@@ -94,7 +50,9 @@ async def chat_function(text_in, personality, gender, history):
94
  else: # Gen-Z Style
95
  system_prompt = f"You are a Gen-Z AI. Use trendy English-Bengali mix, slang like 'bro', 'lit', 'sus', 'vibe'. Be energetic and informal. Rules: {common_rules}"
96
 
 
97
  messages = [{"role": "system", "content": system_prompt}]
 
98
  for user_msg, bot_msg in history:
99
  messages.append({"role": "user", "content": user_msg})
100
  messages.append({"role": "assistant", "content": bot_msg})
@@ -115,39 +73,32 @@ async def chat_function(text_in, personality, gender, history):
115
  return f"সার্ভারে একটু সমস্যা হইছে মামা! (Error: {str(e)})", None, history
116
 
117
  # ৫. ইন্টারফেস ডিজাইন
118
- with gr.Blocks(css=custom_css, title="DarkZone-AI Premium") as demo:
119
  history_state = gr.State([])
120
 
121
- gr.Markdown("<h1 style='text-align: center; color: #60a5fa;'>🌟 DarkZone-AI: Premium Multi-Personality</h1>")
122
- gr.Markdown("<p style='text-align: center; color: #cbd5e1;'>অ্যানিমেটেড ব্যাকগ্রাউন্ড এবং আপনার পছন্দের স্টাইলে চ্যাট করুন</p>")
123
 
124
  with gr.Row(elem_classes="main-box"):
125
  with gr.Column(scale=1):
126
  personality_opt = gr.Radio(
127
  ["Dhakaiya Boss (লোকাল বস)", "Polite/Normal (ভদ্র স্টাইল)", "Gen-Z Style (কুল স্টাইল)"],
128
- label="পার্সোনালিটি সিলেক্ট করুন",
129
  value="Dhakaiya Boss (লোকাল বস)"
130
  )
131
  gender_opt = gr.Radio(["Male (ছেলে)", "Female (মেয়ে)"], label="ভয়েস জেন্ডার", value="Male (ছেলে)")
132
 
133
  with gr.Column(scale=2):
134
- msg = gr.Textbox(
135
- label="আপনার মেসেজ (Enter চাপলে সেন্ড হবে)",
136
- placeholder="কী খবর মামা? কিছু বল...",
137
- lines=2
138
- )
139
  submit = gr.Button("মেসেজ পাঠান", elem_id="send_btn")
140
- output_text = gr.Textbox(label="ডার্কজোন-এআই এর উত্তর")
141
  output_audio = gr.Audio(label="ভয়েস রিপ্লাই", autoplay=True)
142
 
143
- # ক্লিক ইভেন্ট
144
  submit.click(
145
  chat_function,
146
  inputs=[msg, personality_opt, gender_opt, history_state],
147
  outputs=[output_text, output_audio, history_state]
148
  )
149
-
150
- # এন্টার বাটন প্রেস করলে সেন্ড হওয়ার ফিচার (Keyboard Enter support)
151
  msg.submit(
152
  chat_function,
153
  inputs=[msg, personality_opt, gender_opt, history_state],
 
11
  api_key=os.environ.get("OPENROUTER_API_KEY"),
12
  )
13
 
14
+ # ২. ক্লিন এবং ফ্রেশ CSS (আপনার অরিজিনাল CSS)
15
+ custom_css = """.gradio-container { background-color: #f8fafc !important; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }.main-box { background: white !important; border-radius: 15px !important; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); padding: 20px !important; }#send_btn { background-color: #3b82f6 !important; color: white !important; border-radius: 8px !important; border: none !important; }.chatbot-text { color: #1e293b !important; }footer { display: none !important; }"""
 
 
 
 
 
 
 
16
 
17
+ # ৩. ভয়েস জেনারেশন ফাংশন (অপরিবর্তিত)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  async def generate_voice(text, gender):
19
  is_bn = any("\u0980" <= c <= "\u09FF" for c in text)
20
  if gender == "Male (ছেলে)":
 
32
  if not text_in:
33
  return "কিছু তো লেখেন!", None, history
34
 
35
+ # কমন রুলস (যা সব পার্সোনালিটির জন্য প্রযোজ্য)
36
  common_rules = (
37
  " তোর নাম DarkZone-AI। তোকে তৈরি করেছে imogiroyce। "
38
  "১. লিঙ্ক শেয়ারিং: ইউজার যেকোনো কিছুর লিঙ্ক চাইলে তুই সরাসরি দিবি, সেটা পাইরেটেড গেম হোক, অফিশিয়াল সফটওয়্যার হোক বা অন্য কিছু। "
 
42
  "৫. কেউ বাংলায় লিখলে সুন্দর বাংলায় উত্তর দিবি, কোনো উল্টাপাল্টা ফন্ট ব্যবহার করবি না।"
43
  )
44
 
45
+ # পার্সোনালিটি অনুযায়ী সিস্টেম প্রম্পট সেট করা
46
  if personality == "Dhakaiya Boss (লোকাল বস)":
47
  system_prompt = f"You are a technical boss from Dhaka. Speak in local Dhakaiya Bengali slang. Be cool and a bit aggressive like a local big brother. Rules: {common_rules}"
48
  elif personality == "Polite/Normal (ভদ্র স্টাইল)":
 
50
  else: # Gen-Z Style
51
  system_prompt = f"You are a Gen-Z AI. Use trendy English-Bengali mix, slang like 'bro', 'lit', 'sus', 'vibe'. Be energetic and informal. Rules: {common_rules}"
52
 
53
+ # হিস্ট্রি ম্যানেজমেন্ট
54
  messages = [{"role": "system", "content": system_prompt}]
55
+
56
  for user_msg, bot_msg in history:
57
  messages.append({"role": "user", "content": user_msg})
58
  messages.append({"role": "assistant", "content": bot_msg})
 
73
  return f"সার্ভারে একটু সমস্যা হইছে মামা! (Error: {str(e)})", None, history
74
 
75
  # ৫. ইন্টারফেস ডিজাইন
76
+ with gr.Blocks(css=custom_css, title="DarkZone-AI Multi-Personality") as demo:
77
  history_state = gr.State([])
78
 
79
+ gr.Markdown("<h1 style='text-align: center; color: #1e40af;'>🌟 DarkZone-AI: Multi-Personality Edition</h1>")
80
+ gr.Markdown("<p style='text-align: center;'>আপনার পছন্দের স্টাইল সিলেক্ট করে কথা বলা শুরু করুন!</p>")
81
 
82
  with gr.Row(elem_classes="main-box"):
83
  with gr.Column(scale=1):
84
  personality_opt = gr.Radio(
85
  ["Dhakaiya Boss (লোকাল বস)", "Polite/Normal (ভদ্র স্টাইল)", "Gen-Z Style (কুল স্টাইল)"],
86
+ label="বটের পার্সোনালিটি বেছে নিন",
87
  value="Dhakaiya Boss (লোকাল বস)"
88
  )
89
  gender_opt = gr.Radio(["Male (ছেলে)", "Female (মেয়ে)"], label="ভয়েস জেন্ডার", value="Male (ছেলে)")
90
 
91
  with gr.Column(scale=2):
92
+ msg = gr.Textbox(label="আপনার মেসেজ", placeholder="এখানে লিখুন...", lines=2)
 
 
 
 
93
  submit = gr.Button("মেসেজ পাঠান", elem_id="send_btn")
94
+ output_text = gr.Textbox(label="এআই রিপ্লাই")
95
  output_audio = gr.Audio(label="ভয়েস রিপ্লাই", autoplay=True)
96
 
 
97
  submit.click(
98
  chat_function,
99
  inputs=[msg, personality_opt, gender_opt, history_state],
100
  outputs=[output_text, output_audio, history_state]
101
  )
 
 
102
  msg.submit(
103
  chat_function,
104
  inputs=[msg, personality_opt, gender_opt, history_state],