minzo456 commited on
Commit
21319fa
·
verified ·
1 Parent(s): 1c1c345

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -40
app.py CHANGED
@@ -6,23 +6,21 @@ import random
6
  # 🛡️ MASTER SYSTEM KEYS
7
  SERPER_KEY = "3c66e0caba64b253eca2d2ebe5fa8a39cd529671"
8
  GROQ_API_KEY = "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"
9
- STABLE_MODEL = "qwen/qwen3-32b"
10
 
11
- def minzo_chat_logic(message, mode):
12
- """ප්‍රධාන AI තර්කනය"""
13
  try:
14
- if mode == "Visual Forge (Image)":
15
- seed = random.randint(1, 999999)
16
- img_url = f"https://image.pollinations.ai/prompt/{message.replace(' ', '%20')}?nologo=true&seed={seed}&width=1024&height=1024"
17
- return "✅ දෘශ්‍ය සම්පත සාර්ථකව නිර්මාණය කළා.", img_url
18
-
19
- # සජීවී සෙවුම් තොරතුරු (Web Search)
20
  search_context = ""
21
  try:
22
- s_res = requests.post("https://google.serper.dev/search", headers={'X-API-KEY': SERPER_KEY}, json={"q": message}, timeout=5).json()
 
 
23
  search_context = "\n".join([item['snippet'] for item in s_res.get('organic', [])[:2]])
24
  except: pass
25
 
 
26
  headers = {"Authorization": f"Bearer {GROQ_API_KEY}", "Content-Type": "application/json"}
27
  payload = {
28
  "model": STABLE_MODEL,
@@ -36,38 +34,24 @@ def minzo_chat_logic(message, mode):
36
  res_json = r.json()
37
 
38
  if 'choices' in res_json:
39
- return res_json['choices'][0]['message']['content'], None
40
  else:
41
- return "⚠️ පද්ධතිය මොහොතකාර්යහුලයි. කරුණාකර නැවත උත්සාහ කරන්න.", None
42
 
43
  except Exception as e:
44
- return f"⚠️ පද්ධති දෝෂයකි: {str(e)}", None
45
-
46
- # --- 🔱 UI DESIGN ---
47
- # Error එක මඟහැරීම Blocks තුළ කි පරාමතිභාිතා නොකරයි
48
- with gr.Blocks() as demo:
49
- gr.Markdown("# 🔱 MINZO AI | STRATEGIC CHAT CORE")
50
-
51
- # 🛡️ මෝඩලය ෑම Gradio එකක වැඩ කිරීමට රලසැකසීම
52
- chatbot = gr.Chatbot(label="MINZO Neural Link")
53
-
54
- with gr.Row():
55
- msg = gr.Textbox(placeholder="ඔබේ විධානය මෙහි ඇතුළත් කන්න...", scale=9)
56
- submit_btn = gr.Button("EXECUTE", scale=1, variant="primary")
57
-
58
- with gr.Row():
59
- mode = gr.Radio(["Neural Chat", "Visual Forge (Image)"], value="Neural Chat", label="Mission Mode")
60
- output_img = gr.Image(label="Forged Visual", interactive=False)
61
-
62
- def respond(message, chat_history, mode_val):
63
- bot_message, bot_img = minzo_chat_logic(message, mode_val)
64
- # පණිවිඩ Tuple එකක් ලෙස එකතු කිරීම (මෙය සියලුම Gradio වලට ගැලපේ)
65
- chat_history.append((message, bot_message))
66
- return "", chat_history, bot_img
67
-
68
- submit_btn.click(respond, [msg, chatbot, mode], [msg, chatbot, output_img])
69
- msg.submit(respond, [msg, chatbot, mode], [msg, chatbot, output_img])
70
 
71
- # launch() එකේදී theme එක සක්‍රිය කිරීමෙන් Warning එක මඟහැරේ
72
  if __name__ == "__main__":
73
- demo.launch(theme=gr.themes.Soft(primary_hue="orange"))
 
6
  # 🛡️ MASTER SYSTEM KEYS
7
  SERPER_KEY = "3c66e0caba64b253eca2d2ebe5fa8a39cd529671"
8
  GROQ_API_KEY = "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"
9
+ STABLE_MODEL = "qwen-2.5-32b"
10
 
11
+ def minzo_response(message, history):
12
+ """ChatInterface සඳහා අවශ්‍ය ප්‍රධාන තර්කික කොටස"""
13
  try:
14
+ # 🔍 සජීවී සෙවුම් තොරතුරු (Web Search)
 
 
 
 
 
15
  search_context = ""
16
  try:
17
+ s_res = requests.post("https://google.serper.dev/search",
18
+ headers={'X-API-KEY': SERPER_KEY},
19
+ json={"q": message}, timeout=5).json()
20
  search_context = "\n".join([item['snippet'] for item in s_res.get('organic', [])[:2]])
21
  except: pass
22
 
23
+ # 🧠 AI සංවාදය
24
  headers = {"Authorization": f"Bearer {GROQ_API_KEY}", "Content-Type": "application/json"}
25
  payload = {
26
  "model": STABLE_MODEL,
 
34
  res_json = r.json()
35
 
36
  if 'choices' in res_json:
37
+ return res_json['choices'][0]['message']['content']
38
  else:
39
+ return "⚠️ Groq පද්ධතිය ්බන්ධ වීමේ බාධාවකි. නැවත උත්සාහ කරන්න."
40
 
41
  except Exception as e:
42
+ return f"⚠️ තාක්ෂණ දෝෂයකි: {str(e)}"
43
+
44
+ # --- 🔱 UI DESIGN (ULTIMATE COMPATIBILITY) ---
45
+ # ChatInterface භාවිතා කිරීමෙන් 'role'හ 'content' ෝෂ ිය ස්යං්‍ව වසඳේ.
46
+ demo = gr.ChatInterface(
47
+ fn=minzo_response,
48
+ title="🔱 MINZO AI | STRATEGIC CORE",
49
+ description="Commander MINZO-PRIME සඳහා සෘජුන්නිේදන පද්ධතිය.",
50
+ theme=gr.themes.Soft(primary_hue="orange", neutral_hue="slate"),
51
+ retry_btn="නැවත උත්සාහ කරන්න",
52
+ undo_btn="මකන්න",
53
+ clear_btn="්පූර්ණය කන්න",
54
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
 
56
  if __name__ == "__main__":
57
+ demo.launch()