anaspro
commited on
Commit
·
eded289
1
Parent(s):
a241f94
updatE
Browse files
app.py
CHANGED
|
@@ -127,10 +127,9 @@ def detect_language(text):
|
|
| 127 |
|
| 128 |
@spaces.GPU()
|
| 129 |
def generate_response(input_data, chat_history, max_new_tokens, temperature, top_p, top_k, repetition_penalty):
|
| 130 |
-
#
|
| 131 |
conversation_parts = []
|
| 132 |
|
| 133 |
-
# Add chat history
|
| 134 |
if chat_history:
|
| 135 |
for item in chat_history:
|
| 136 |
role = item["role"]
|
|
@@ -143,33 +142,34 @@ def generate_response(input_data, chat_history, max_new_tokens, temperature, top
|
|
| 143 |
elif role == "assistant":
|
| 144 |
conversation_parts.append(f"[|AI|] {content}")
|
| 145 |
|
| 146 |
-
#
|
| 147 |
conversation_parts.append(f"[|Human|] {input_data}")
|
| 148 |
|
| 149 |
-
#
|
| 150 |
conversation = "\n".join(conversation_parts)
|
| 151 |
-
|
| 152 |
-
# Create full prompt using the Iraqi Arabic prompt template
|
| 153 |
full_prompt = prompt_ar.format(Question=conversation)
|
| 154 |
|
| 155 |
try:
|
| 156 |
-
# استخدام دالة get_response من documentation
|
| 157 |
response = get_response(full_prompt)
|
| 158 |
|
| 159 |
-
# استخراج الرد الجديد فقط
|
| 160 |
if "### Response :" in response:
|
| 161 |
response = response.split("### Response :")[-1].strip()
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
|
|
|
|
| 167 |
|
| 168 |
except Exception as e:
|
| 169 |
print(f"Error in generate_response: {e}")
|
| 170 |
import traceback
|
| 171 |
print(traceback.format_exc())
|
| 172 |
-
|
| 173 |
|
| 174 |
demo = gr.ChatInterface(
|
| 175 |
fn=generate_response,
|
|
|
|
| 127 |
|
| 128 |
@spaces.GPU()
|
| 129 |
def generate_response(input_data, chat_history, max_new_tokens, temperature, top_p, top_k, repetition_penalty):
|
| 130 |
+
# بناء المحادثة بنمط الموديل العراقي
|
| 131 |
conversation_parts = []
|
| 132 |
|
|
|
|
| 133 |
if chat_history:
|
| 134 |
for item in chat_history:
|
| 135 |
role = item["role"]
|
|
|
|
| 142 |
elif role == "assistant":
|
| 143 |
conversation_parts.append(f"[|AI|] {content}")
|
| 144 |
|
| 145 |
+
# أضف الرسالة الحالية
|
| 146 |
conversation_parts.append(f"[|Human|] {input_data}")
|
| 147 |
|
| 148 |
+
# إنشاء البرومبت الكامل
|
| 149 |
conversation = "\n".join(conversation_parts)
|
|
|
|
|
|
|
| 150 |
full_prompt = prompt_ar.format(Question=conversation)
|
| 151 |
|
| 152 |
try:
|
|
|
|
| 153 |
response = get_response(full_prompt)
|
| 154 |
|
| 155 |
+
# استخراج الرد الجديد فقط بعد ### Response :
|
| 156 |
if "### Response :" in response:
|
| 157 |
response = response.split("### Response :")[-1].strip()
|
| 158 |
|
| 159 |
+
# إزالة أي محتوى إضافي أو markers
|
| 160 |
+
if "[|Human|]" in response:
|
| 161 |
+
response = response.split("[|Human|]")[0].strip()
|
| 162 |
+
if "[|AI|]" in response:
|
| 163 |
+
response = response.replace("[|AI|]", "").strip()
|
| 164 |
|
| 165 |
+
# ✅ رجّع فقط الرد، مو البرومبت الكامل
|
| 166 |
+
return response if response else "هلا، ويّاك أليكس من دعم TechSolutions، شلون أگدر أساعدك اليوم؟"
|
| 167 |
|
| 168 |
except Exception as e:
|
| 169 |
print(f"Error in generate_response: {e}")
|
| 170 |
import traceback
|
| 171 |
print(traceback.format_exc())
|
| 172 |
+
return "هلا، ويّاك أليكس من دعم TechSolutions، شلون أگدر أساعدك اليوم؟"
|
| 173 |
|
| 174 |
demo = gr.ChatInterface(
|
| 175 |
fn=generate_response,
|