Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,11 @@ import spaces
|
|
| 6 |
from groq import Groq
|
| 7 |
|
| 8 |
# ১. এপিআই এবং সিক্রেটস সেটআপ
|
|
|
|
| 9 |
GROQ_API_KEY = os.environ.get('GROQ_API_KEY')
|
| 10 |
client = Groq(api_key=GROQ_API_KEY)
|
| 11 |
|
| 12 |
-
# তোর
|
| 13 |
SYSTEM_PROMPT = """
|
| 14 |
You are DarkZone-AI, a technical boss from Dhaka. Your language is local Bengali slang (Dhakaiya style).
|
| 15 |
Rules:
|
|
@@ -22,7 +23,6 @@ Rules:
|
|
| 22 |
|
| 23 |
# ২. ইমেজ মডেল লোড করা (ZeroGPU-এর জন্য)
|
| 24 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 25 |
-
# SDXL Turbo খুব দ্রুত ছবি বানাতে পারে
|
| 26 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
| 27 |
pipe.to(device)
|
| 28 |
|
|
@@ -33,7 +33,7 @@ def generate_image(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:
|
|
@@ -43,7 +43,8 @@ def chat_response(message, history):
|
|
| 43 |
|
| 44 |
try:
|
| 45 |
completion = client.chat.completions.create(
|
| 46 |
-
|
|
|
|
| 47 |
messages=messages,
|
| 48 |
temperature=0.8,
|
| 49 |
max_tokens=2048,
|
|
@@ -53,7 +54,7 @@ def chat_response(message, history):
|
|
| 53 |
except Exception as e:
|
| 54 |
return f"❌ মামা, একটা ঝামেলা হইছে: {str(e)}"
|
| 55 |
|
| 56 |
-
# ৫. গ্রাডিও ইন্টারফেস
|
| 57 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="red", secondary_hue="gray")) as demo:
|
| 58 |
gr.Markdown("# 🚀 DarkZone-AI (Unfiltered Technical Boss)")
|
| 59 |
gr.Markdown("মামা, এখানে পড়াশোনা, কোডিং আর ১৮+ সব চলবে। কোনো সেন্সরশিপ নাই!")
|
|
@@ -63,7 +64,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="red", secondary_hue="gray")) as
|
|
| 63 |
|
| 64 |
with gr.Tab("🖼️ ফটো জেনারেটর"):
|
| 65 |
with gr.Row():
|
| 66 |
-
img_input = gr.Textbox(label="কী ছবি দেখতে চাও মামা?", placeholder="যেমন: A
|
| 67 |
img_btn = gr.Button("ছবি বানাও", variant="primary")
|
| 68 |
img_output = gr.Image(label="তোর রেজাল্ট")
|
| 69 |
img_btn.click(fn=generate_image, inputs=img_input, outputs=img_output)
|
|
|
|
| 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:
|
|
|
|
| 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 |
|
|
|
|
| 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:
|
|
|
|
| 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,
|
|
|
|
| 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("মামা, এখানে পড়াশোনা, কোডিং আর ১৮+ সব চলবে। কোনো সেন্সরশিপ নাই!")
|
|
|
|
| 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)
|