Update app.py
Browse files
app.py
CHANGED
|
@@ -29,13 +29,6 @@ def chat(message, history):
|
|
| 29 |
|
| 30 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 31 |
|
| 32 |
-
for item in history:
|
| 33 |
-
messages.append({"role": "user", "content": item["content"] if isinstance(item, dict) and item.get("role") == "user" else (item[0] if isinstance(item, (list, tuple)) else "")})
|
| 34 |
-
if isinstance(item, dict) and item.get("role") == "assistant":
|
| 35 |
-
messages.append({"role": "assistant", "content": item["content"]})
|
| 36 |
-
|
| 37 |
-
# بناء التاريخ بشكل صحيح
|
| 38 |
-
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 39 |
for item in history:
|
| 40 |
if isinstance(item, dict):
|
| 41 |
if item.get("role") in ["user", "assistant"]:
|
|
@@ -64,10 +57,39 @@ def chat(message, history):
|
|
| 64 |
return "", history
|
| 65 |
|
| 66 |
css = """
|
|
|
|
|
|
|
| 67 |
.gradio-container {
|
| 68 |
-
font-family: 'Tajawal', sans-serif;
|
| 69 |
-
direction: rtl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
.main-header {
|
| 72 |
background: linear-gradient(135deg, #0a0a0a, #1a1a2e, #16213e);
|
| 73 |
padding: 30px;
|
|
@@ -77,6 +99,7 @@ css = """
|
|
| 77 |
border: 1px solid #00ff88;
|
| 78 |
box-shadow: 0 0 30px rgba(0,255,136,0.2);
|
| 79 |
}
|
|
|
|
| 80 |
.tip-box {
|
| 81 |
background: #0d1117;
|
| 82 |
border: 1px solid #30363d;
|
|
@@ -85,13 +108,22 @@ css = """
|
|
| 85 |
padding: 15px;
|
| 86 |
margin-top: 10px;
|
| 87 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
footer { display: none !important; }
|
| 89 |
"""
|
| 90 |
|
| 91 |
with gr.Blocks(title="درع - المساعد الأمني العربي") as demo:
|
| 92 |
|
| 93 |
gr.HTML("""
|
| 94 |
-
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
|
| 95 |
<div class="main-header">
|
| 96 |
<h1 style="color:#00ff88; margin:0; font-size:2.5em;">🛡️ درع</h1>
|
| 97 |
<h2 style="color:white; margin:10px 0 5px 0; font-size:1.3em;">
|
|
@@ -109,6 +141,7 @@ with gr.Blocks(title="درع - المساعد الأمني العربي") as dem
|
|
| 109 |
label="",
|
| 110 |
height=500,
|
| 111 |
show_label=False,
|
|
|
|
| 112 |
avatar_images=(
|
| 113 |
"https://api.dicebear.com/7.x/avataaars/svg?seed=user",
|
| 114 |
"https://api.dicebear.com/7.x/bottts/svg?seed=shield"
|
|
@@ -151,6 +184,19 @@ with gr.Blocks(title="درع - المساعد الأمني العربي") as dem
|
|
| 151 |
</div>
|
| 152 |
""")
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
send_btn.click(
|
| 155 |
fn=chat,
|
| 156 |
inputs=[msg_input, chatbot],
|
|
|
|
| 29 |
|
| 30 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
for item in history:
|
| 33 |
if isinstance(item, dict):
|
| 34 |
if item.get("role") in ["user", "assistant"]:
|
|
|
|
| 57 |
return "", history
|
| 58 |
|
| 59 |
css = """
|
| 60 |
+
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap');
|
| 61 |
+
|
| 62 |
.gradio-container {
|
| 63 |
+
font-family: 'Tajawal', sans-serif !important;
|
| 64 |
+
direction: rtl !important;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* إصلاح اتجاه الرسائل */
|
| 68 |
+
.message-wrap {
|
| 69 |
+
direction: rtl !important;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/* رسائل المستخدم - يسار */
|
| 73 |
+
.message.user-message,
|
| 74 |
+
[data-testid="user"] {
|
| 75 |
+
direction: rtl !important;
|
| 76 |
+
text-align: right !important;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/* رسائل المساعد - يمين */
|
| 80 |
+
.message.bot-message,
|
| 81 |
+
[data-testid="bot"] {
|
| 82 |
+
direction: rtl !important;
|
| 83 |
+
text-align: right !important;
|
| 84 |
}
|
| 85 |
+
|
| 86 |
+
/* محتوى الرسائل */
|
| 87 |
+
.prose, .prose p, .prose li {
|
| 88 |
+
direction: rtl !important;
|
| 89 |
+
text-align: right !important;
|
| 90 |
+
font-family: 'Tajawal', sans-serif !important;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
.main-header {
|
| 94 |
background: linear-gradient(135deg, #0a0a0a, #1a1a2e, #16213e);
|
| 95 |
padding: 30px;
|
|
|
|
| 99 |
border: 1px solid #00ff88;
|
| 100 |
box-shadow: 0 0 30px rgba(0,255,136,0.2);
|
| 101 |
}
|
| 102 |
+
|
| 103 |
.tip-box {
|
| 104 |
background: #0d1117;
|
| 105 |
border: 1px solid #30363d;
|
|
|
|
| 108 |
padding: 15px;
|
| 109 |
margin-top: 10px;
|
| 110 |
}
|
| 111 |
+
|
| 112 |
+
.developer-box {
|
| 113 |
+
background: linear-gradient(135deg, #0d1117, #1a1a2e);
|
| 114 |
+
border: 1px solid #00ff88;
|
| 115 |
+
border-radius: 10px;
|
| 116 |
+
padding: 15px;
|
| 117 |
+
margin-top: 15px;
|
| 118 |
+
text-align: center;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
footer { display: none !important; }
|
| 122 |
"""
|
| 123 |
|
| 124 |
with gr.Blocks(title="درع - المساعد الأمني العربي") as demo:
|
| 125 |
|
| 126 |
gr.HTML("""
|
|
|
|
| 127 |
<div class="main-header">
|
| 128 |
<h1 style="color:#00ff88; margin:0; font-size:2.5em;">🛡️ درع</h1>
|
| 129 |
<h2 style="color:white; margin:10px 0 5px 0; font-size:1.3em;">
|
|
|
|
| 141 |
label="",
|
| 142 |
height=500,
|
| 143 |
show_label=False,
|
| 144 |
+
rtl=True,
|
| 145 |
avatar_images=(
|
| 146 |
"https://api.dicebear.com/7.x/avataaars/svg?seed=user",
|
| 147 |
"https://api.dicebear.com/7.x/bottts/svg?seed=shield"
|
|
|
|
| 184 |
</div>
|
| 185 |
""")
|
| 186 |
|
| 187 |
+
# قسم المطور
|
| 188 |
+
gr.HTML("""
|
| 189 |
+
<div class="developer-box" style="direction:rtl;">
|
| 190 |
+
<p style="color:#8b949e; margin:0 0 8px 0; font-size:0.85em;">⚙️ تطوير وإعداد</p>
|
| 191 |
+
<p style="color:#00ff88; margin:0; font-size:1em; font-weight:bold;">
|
| 192 |
+
د. معاذ الصوفي
|
| 193 |
+
</p>
|
| 194 |
+
<p style="color:#8b949e; margin:5px 0 0 0; font-size:0.8em;">
|
| 195 |
+
متخصص في الأمن السيبراني
|
| 196 |
+
</p>
|
| 197 |
+
</div>
|
| 198 |
+
""")
|
| 199 |
+
|
| 200 |
send_btn.click(
|
| 201 |
fn=chat,
|
| 202 |
inputs=[msg_input, chatbot],
|