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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -5,51 +5,59 @@ import requests
5
  import base64
6
  import urllib.parse
7
 
8
- # 🔱 CONFIGURATION
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
- TEXT_MODEL = "google/gemma-4-31B-it"
 
11
 
12
  client = InferenceClient(token=HF_TOKEN)
13
 
14
  def dual_engine(message, history):
15
- # 🔱 IMAGE GENERATION (POLLINATIONS AI - UPGRADED)
16
  if message.lower().startswith("/image "):
17
  prompt = message.replace("/image ", "").strip()
18
-
19
- # ⚠️ PROMPT එක ආරක්ෂිතව URL එකකට හැරවීම (Encoding)
20
  safe_prompt = urllib.parse.quote(prompt)
21
-
22
- # වඩාත් ස්ථාවර URL එක සහ පරාමිතීන් (Flux Model & No Logo)
23
  image_url = f"https://image.pollinations.ai/prompt/{safe_prompt}?width=1024&height=1024&nologo=true&model=flux&enhance=true"
24
 
25
  try:
26
- # පින්තූරය ලබා ගැනීමට උත්සාහ කිරීම (Timeout එකක් සහිතව)
27
  response = requests.get(image_url, timeout=30)
28
-
29
  if response.status_code == 200:
30
- # පින්තූර දත්ත Base64 ලෙස සැකසීම
31
  img_str = base64.b64encode(response.content).decode()
32
  return f"IMAGE_DATA:data:image/png;base64,{img_str}"
33
  else:
34
- return f"⚠️ Engine Busy (Status: {response.status_code}). පණිවිඩය කෙටි කර නැවත උත්සාහ කරන්න."
35
-
36
- except Exception as e:
37
- return f"⚠️ Uplink Error: පද්ධතිය කාර්යබහුලයි. තත්පර කිහිපයකින් නැවත උත්සාහ කරන්න."
38
 
39
- # 🔱 TEXT CHAT (GEMMA-4)
40
  else:
41
- # (පෙර පරිදිම Text Chat කේත මෙහි තිබිය යය)
42
- messages = [{"role": "system", "content": "නම: MINZO AI. නිර්මාතෘ: MINZO-PRIME."}]
 
 
 
 
 
 
 
 
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(messages, model=TEXT_MODEL, max_tokens=1024)
 
 
 
 
 
 
50
  return response.choices[0].message.content
51
  except Exception as e:
52
- return f"⚠️ Text Core Error: {str(e)}"
53
 
54
  # Gradio Interface
55
  demo = gr.ChatInterface(fn=dual_engine, api_name="chat")
 
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)
 
 
20
  image_url = f"https://image.pollinations.ai/prompt/{safe_prompt}?width=1024&height=1024&nologo=true&model=flux&enhance=true"
21
 
22
  try:
 
23
  response = requests.get(image_url, timeout=30)
 
24
  if response.status_code == 200:
 
25
  img_str = base64.b64encode(response.content).decode()
26
  return f"IMAGE_DATA:data:image/png;base64,{img_str}"
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")