Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,15 @@ import requests
|
|
| 5 |
import base64
|
| 6 |
import urllib.parse
|
| 7 |
|
| 8 |
-
# 🔱 CONFIGURATION (
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
-
# ල
|
| 11 |
-
TEXT_MODEL = "
|
| 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,37 +27,34 @@ def dual_engine(message, history):
|
|
| 27 |
else:
|
| 28 |
return "⚠️ Image Engine Busy. Please retry."
|
| 29 |
except Exception:
|
| 30 |
-
return "⚠️ Connection Error.
|
| 31 |
-
|
| 32 |
-
# 🔱 TEXT CHAT (
|
| 33 |
else:
|
| 34 |
-
#
|
| 35 |
system_instruction = (
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"
|
|
|
|
| 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
|
| 60 |
-
return
|
| 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")
|