minzo456 commited on
Commit
b7ef2b3
·
verified ·
1 Parent(s): 22ae2e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -19
app.py CHANGED
@@ -5,15 +5,15 @@ import requests
5
  import base64
6
  import urllib.parse
7
 
8
- # 🔱 CONFIGURATION (UPGRADED TO QWEN 72B - CLAUDE LEVEL)
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
- # ලෝකයේ දැනට පවති ප්‍රබලතම මාදිලික්
11
- TEXT_MODEL = "Qwen/Qwen2.5-72B-Instruct"
12
 
13
  client = InferenceClient(token=HF_TOKEN)
14
 
15
  def dual_engine(message, history):
16
- # 🔱 IMAGE GENERATION (POLLINATIONS FLUX ENGINE)
17
  if message.lower().startswith("/image "):
18
  prompt = message.replace("/image ", "").strip()
19
  safe_prompt = urllib.parse.quote(prompt)
@@ -27,37 +27,34 @@ def dual_engine(message, history):
27
  else:
28
  return "⚠️ Image Engine Busy. Please retry."
29
  except Exception:
30
- return "⚠️ Connection Error. Please retry."
31
-
32
- # 🔱 TEXT CHAT (UPGRADED BRAIN)
33
  else:
34
- # System Instructions ු කිරීම
35
  system_instruction = (
36
- "ඔබේ නම MINZO AI. ඔබ නිර්මාණය කළේ MINZO-PRIME විසින්. "
37
- "ඔබ ඉතාමත් බුද්ධිමත්, තාක්ෂණික දැනුම ඇති සහ උදව්ශීලී සහායෙකු ලෙස හැසිරෙන්න. "
38
- "පින්තූර නිපදවීමට /image විධානය භාවිතා කිරීමට පරිශීලකයාට උපදෙස් දෙන්න."
 
39
  )
40
 
41
  messages = [{"role": "system", "content": system_instruction}]
42
-
43
- # කලින් කතා කළ දේ මතක තබා ගැනීම (Memory)
44
  for user_msg, assistant_msg in history:
45
  messages.append({"role": "user", "content": user_msg})
46
  messages.append({"role": "assistant", "content": assistant_msg})
47
-
48
  messages.append({"role": "user", "content": message})
49
 
50
  try:
51
- # Qwen 72B හරහා පිළිතුර ලබා ගැනීම
52
  response = client.chat_completion(
53
  messages,
54
  model=TEXT_MODEL,
55
- max_tokens=1500, # දිගු පිළිතුරු ලබා දීමට
56
- temperature=0.7 # වඩිර්මාණශලී වීමට
57
  )
58
  return response.choices[0].message.content
59
- except Exception as e:
60
- return f"⚠️ Brain Core Error: පද්ධතියේ අධික තබදයක් පවතිනවා. පසුව උත්සාහ කරන්න."
61
 
62
  # Gradio Interface
63
  demo = gr.ChatInterface(fn=dual_engine, api_name="chat")
 
5
  import base64
6
  import urllib.parse
7
 
8
+ # 🔱 CONFIGURATION (NATURAL SINHALA ENGINE)
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
+ # සිංහභාෂාව සඳහා දැනට ති හොඳOpen-source ොළ
11
+ TEXT_MODEL = "meta-llama/Meta-Llama-3.1-8B-Instruct"
12
 
13
  client = InferenceClient(token=HF_TOKEN)
14
 
15
  def dual_engine(message, history):
16
+ # 🔱 IMAGE GENERATION (POLLINATIONS FLUX)
17
  if message.lower().startswith("/image "):
18
  prompt = message.replace("/image ", "").strip()
19
  safe_prompt = urllib.parse.quote(prompt)
 
27
  else:
28
  return "⚠️ Image Engine Busy. Please retry."
29
  except Exception:
30
+ return "⚠️ Connection Error."
31
+
32
+ # 🔱 TEXT CHAT (LLAMA 3.1 - NATURAL SINHALA)
33
  else:
34
+ # සිංහලෙන් වඩාත් හොඳන් පිළිතදීමට System Prompt එ සැකසීම
35
  system_instruction = (
36
+ "You are MINZO AI, created by MINZO-PRIME. "
37
+ "You must communicate in natural, fluent Sinhala. "
38
+ "Helpful, brilliant, and strategic in your responses. "
39
+ "පින්තූර සෑදීමට /image විධානය භාවිතා කරන්න."
40
  )
41
 
42
  messages = [{"role": "system", "content": system_instruction}]
 
 
43
  for user_msg, assistant_msg in history:
44
  messages.append({"role": "user", "content": user_msg})
45
  messages.append({"role": "assistant", "content": assistant_msg})
 
46
  messages.append({"role": "user", "content": message})
47
 
48
  try:
 
49
  response = client.chat_completion(
50
  messages,
51
  model=TEXT_MODEL,
52
+ max_tokens=1500,
53
+ temperature=0.7 # සිංහල ගලයාම සවාභාවික ිරීමට
54
  )
55
  return response.choices[0].message.content
56
+ except Exception:
57
+ return "⚠️ පද්ධතියේ දෝෂයක්. කරණාකර නැ උත්සාහ කරන්න."
58
 
59
  # Gradio Interface
60
  demo = gr.ChatInterface(fn=dual_engine, api_name="chat")