Update app.py
Browse files
app.py
CHANGED
@@ -17,27 +17,24 @@ nltk.download('punkt')
|
|
17 |
|
18 |
st.markdown("""
|
19 |
<style>
|
20 |
-
/* استایل برای هدر */
|
21 |
.stAppHeader.st-emotion-cache-12fmjuu.e4hpqof0 {
|
22 |
-
background-color: rgba(46,59,46, 0.8) !important;
|
23 |
-
color: #2e3b2e !important;
|
24 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
25 |
-
padding: 20px !important;
|
26 |
-
border-radius: 10px !important;
|
27 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
28 |
}
|
29 |
</style>
|
30 |
""", unsafe_allow_html=True)
|
31 |
st.markdown("""
|
32 |
<style>
|
33 |
-
/* بارگذاری فونت Roboto */
|
34 |
@font-face {
|
35 |
font-family: 'Roboto';
|
36 |
src: url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap') format('woff2');
|
37 |
font-weight: 400;
|
38 |
font-style: normal;
|
39 |
}
|
40 |
-
/* تنظیم فونت برای کل سایت */
|
41 |
html, body, [class*="css"] {
|
42 |
font-family: 'Roboto', Tahoma, sans-serif !important;
|
43 |
font-weight: 400 !important;
|
@@ -45,19 +42,16 @@ st.markdown("""
|
|
45 |
text-align: right;
|
46 |
ظ color: #ffffff;
|
47 |
}
|
48 |
-
/* طراحی برای بخش استایل اپ */
|
49 |
.stApp {
|
50 |
background: linear-gradient(to left, #4b5e40, #2e3b2e);
|
51 |
color: #ffffff;
|
52 |
}
|
53 |
-
/* استایل برای سایدبار */
|
54 |
[data-testid="stSidebar"] {
|
55 |
width: 260px !important;
|
56 |
background-color: #1a2b1e;
|
57 |
border: none !important;
|
58 |
padding-top: 20px;
|
59 |
}
|
60 |
-
/* استایل برای آیتمهای منو */
|
61 |
.menu-item {
|
62 |
display: flex;
|
63 |
align-items: center;
|
@@ -69,17 +63,14 @@ st.markdown("""
|
|
69 |
cursor: pointer;
|
70 |
transition: background-color 0.3s ease;
|
71 |
}
|
72 |
-
/* استایل برای آیتمهای منو هنگام هاور */
|
73 |
.menu-item:hover {
|
74 |
background-color: #2e3b2e;
|
75 |
color: #b8860b;
|
76 |
}
|
77 |
-
/* استایل برای آیکونها در منو */
|
78 |
.menu-item img {
|
79 |
width: 25px;
|
80 |
height: 25px;
|
81 |
}
|
82 |
-
/* استایل برای دکمهها */
|
83 |
.stButton>button {
|
84 |
background-color: #b8860b !important;
|
85 |
color: #1a2b1e !important;
|
@@ -93,13 +84,11 @@ st.markdown("""
|
|
93 |
width: 100%;
|
94 |
margin: 10px 0;
|
95 |
}
|
96 |
-
/* استایل برای دکمهها هنگام هاور */
|
97 |
.stButton>button:hover {
|
98 |
background-color: #8b6508 !important;
|
99 |
transform: translateY(-2px);
|
100 |
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
|
101 |
}
|
102 |
-
/* استایل برای متن هدر */
|
103 |
.header-text {
|
104 |
text-align: center;
|
105 |
margin: 20px 0;
|
@@ -109,14 +98,12 @@ st.markdown("""
|
|
109 |
box-shadow: 0 6px 12px rgba(0,0,0,0.4);
|
110 |
font-family: 'Roboto', Tahoma, sans-serif; /* اضافه شد */
|
111 |
}
|
112 |
-
/* استایل برای زیرنویس */
|
113 |
.subtitle {
|
114 |
font-size: 18px;
|
115 |
color: #d4d4d4;
|
116 |
font-weight: 600;
|
117 |
margin-top: 10px;
|
118 |
}
|
119 |
-
/* استایل برای پیامهای چت */
|
120 |
.chat-message {
|
121 |
flex-wrap: wrap;
|
122 |
background-color: rgba(26, 43, 30, 0.95);
|
@@ -134,12 +121,10 @@ st.markdown("""
|
|
134 |
align-items: center;
|
135 |
gap: 15px;
|
136 |
}
|
137 |
-
/* انیمیشن برای ورود پیام چت */
|
138 |
@keyframes fadeIn {
|
139 |
from { opacity: 0; transform: translateY(10px); }
|
140 |
to { opacity: 1; transform: translateY(0); }
|
141 |
}
|
142 |
-
/* استایل برای ورودی متن */
|
143 |
.stTextInput>div>input, .stTextArea textarea {
|
144 |
background-color: rgba(26, 43, 30, 0.95) !important;
|
145 |
border-radius: 10px !important;
|
@@ -150,12 +135,10 @@ st.markdown("""
|
|
150 |
font-size: 16px;
|
151 |
color: #d4d4d4 !important;
|
152 |
}
|
153 |
-
/* استایل برای خط افقی */
|
154 |
hr {
|
155 |
border: 1px solid #b8860b;
|
156 |
margin: 15px 0;
|
157 |
}
|
158 |
-
/* حذف مرز از قسمت سایدبار */
|
159 |
[data-testid="stSidebar"] > div {
|
160 |
border: none !important;
|
161 |
}
|
@@ -163,7 +146,6 @@ st.markdown("""
|
|
163 |
""", unsafe_allow_html=True)
|
164 |
|
165 |
|
166 |
-
# ---------- احراز هویت ----------
|
167 |
if "authenticated" not in st.session_state:
|
168 |
st.session_state.authenticated = False
|
169 |
|
@@ -182,11 +164,9 @@ if not st.session_state.authenticated:
|
|
182 |
""", unsafe_allow_html=True)
|
183 |
st.markdown("""
|
184 |
<style>
|
185 |
-
/* فونت عمومی */
|
186 |
html, body, [class*="css"] {
|
187 |
font-family: 'Vazir', sans-serif;
|
188 |
}
|
189 |
-
/* استایل برای برچسب فیلدهای ورودی */
|
190 |
label {
|
191 |
font-size: 20px !important;
|
192 |
color: #ffffff !important;
|
@@ -194,7 +174,6 @@ if not st.session_state.authenticated:
|
|
194 |
margin-bottom: 10px !important;
|
195 |
display: block;
|
196 |
}
|
197 |
-
/* استایل برای ورودیها در تمام حالتها */
|
198 |
input[type="text"],
|
199 |
input[type="password"],
|
200 |
input[type="text"]:focus,
|
@@ -261,7 +240,6 @@ if not st.session_state.authenticated:
|
|
261 |
""", unsafe_allow_html=True)
|
262 |
st.stop()
|
263 |
|
264 |
-
# ---------- سایدبار ----------
|
265 |
with st.sidebar:
|
266 |
st.image("log.png", use_container_width=True)
|
267 |
|
@@ -297,11 +275,10 @@ with st.sidebar:
|
|
297 |
|
298 |
st.markdown("""
|
299 |
<style>
|
300 |
-
/* استایل برای متن هدر */
|
301 |
.header-text {
|
302 |
text-align: center;
|
303 |
margin: 50px 0;
|
304 |
-
background: #2e3b2e;
|
305 |
padding: 60px 30px;
|
306 |
border-radius: 25px;
|
307 |
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.8); /* سایه بیشتر */
|
@@ -310,7 +287,6 @@ st.markdown("""
|
|
310 |
background-position: center;
|
311 |
position: relative;
|
312 |
}
|
313 |
-
/* انیمیشن ورودی */
|
314 |
@keyframes fadeIn {
|
315 |
0% { opacity: 0; transform: translateY(30px); }
|
316 |
100% { opacity: 1; transform: translateY(0); }
|
@@ -319,19 +295,17 @@ st.markdown("""
|
|
319 |
0% { transform: translateX(-50%); opacity: 0; }
|
320 |
100% { transform: translateX(0); opacity: 1; }
|
321 |
}
|
322 |
-
/* تغییر فونت برای h1 */
|
323 |
.header-text h1 {
|
324 |
font-family: 'Vazir', sans-serif;
|
325 |
font-size: 62px;
|
326 |
-
color: #d89b00;
|
327 |
margin: 0;
|
328 |
font-weight: 900;
|
329 |
letter-spacing: 4px;
|
330 |
-
text-shadow: 4px 4px 15px rgba(0, 0, 0, 0.9);
|
331 |
-
transform: scale(1.08);
|
332 |
animation: glow 2s ease-in-out infinite alternate;
|
333 |
}
|
334 |
-
/* تغییر استایل زیرعنوان */
|
335 |
.subtitle {
|
336 |
font-family: 'Vazir', sans-serif;
|
337 |
font-size: 24px;
|
@@ -339,17 +313,15 @@ st.markdown("""
|
|
339 |
font-weight: 700;
|
340 |
margin-top: 15px;
|
341 |
letter-spacing: 2px;
|
342 |
-
text-shadow: 3px 3px 10px rgba(0,0,0,0.8);
|
343 |
animation: fadeInSubtitle 2s ease-in-out;
|
344 |
}
|
345 |
-
/* انیمیشن زیرعنوان */
|
346 |
@keyframes fadeInSubtitle {
|
347 |
0% { opacity: 0; transform: translateY(20px); }
|
348 |
100% { opacity: 1; transform: translateY(0); }
|
349 |
}
|
350 |
-
/* استایل برای دکمهها */
|
351 |
.stButton>button {
|
352 |
-
background-color: #e67e22 !important;
|
353 |
color: #4b5320 !important;
|
354 |
font-family: 'Vazir', sans-serif;
|
355 |
font-weight: 700 !important;
|
@@ -367,9 +339,8 @@ st.markdown("""
|
|
367 |
transform: translateY(-4px);
|
368 |
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
|
369 |
}
|
370 |
-
/* استایل برای استایل کلی صفحه */
|
371 |
.stApp {
|
372 |
-
background: #2e3b2e;
|
373 |
color: white;
|
374 |
font-family: 'Vazir', sans-serif;
|
375 |
}
|
@@ -380,7 +351,6 @@ st.markdown("""
|
|
380 |
</div>
|
381 |
""", unsafe_allow_html=True)
|
382 |
|
383 |
-
# ---------- مدل زبانی ----------
|
384 |
llm = ChatOpenAI(
|
385 |
base_url="https://api.together.xyz/v1",
|
386 |
api_key='0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979',
|
@@ -395,17 +365,15 @@ llm = ChatOpenAI(
|
|
395 |
|
396 |
# llm = pipeline("text-generation", model=model_name)
|
397 |
|
398 |
-
# ---------- ورودی جستجو ----------
|
399 |
st.markdown("""
|
400 |
<style>
|
401 |
-
/* استایل برای کلاس خاص st-emotion-cache-128upt6 eht7o1d3 */
|
402 |
.st-emotion-cache-128upt6.eht7o1d3 {
|
403 |
-
background-color: rgba(46,59,46, 0.8) !important;
|
404 |
-
border-radius: 10px !important;
|
405 |
-
color: #d4d4d4 !important;
|
406 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
407 |
-
padding: 15px !important;
|
408 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
409 |
}
|
410 |
</style>
|
411 |
""", unsafe_allow_html=True)
|
@@ -425,41 +393,37 @@ st.markdown("""
|
|
425 |
|
426 |
st.markdown("""
|
427 |
<style>
|
428 |
-
/* استایل برای کلاس st-emotion-cache-yd4u6l e1togvvn1 */
|
429 |
.st-emotion-cache-yd4u6l.e1togvvn1 {
|
430 |
-
background-color: rgba(106, 127, 83, 0.8) !important;
|
431 |
-
border-radius: 10px !important;
|
432 |
-
color: #d4d4d4 !important;
|
433 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
434 |
-
padding: 15px !important;
|
435 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
436 |
}
|
437 |
</style>
|
438 |
""", unsafe_allow_html=True)
|
439 |
st.markdown("""
|
440 |
<style>
|
441 |
-
/* استایل برای هدر */
|
442 |
.stAppHeader.st-emotion-cache-12fmjuu.e4hpqof0 {
|
443 |
-
background-color: rgba(42, 55, 39, 0.9) !important;
|
444 |
-
color: #d4d4d4 !important;
|
445 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
446 |
-
padding: 20px !important;
|
447 |
-
border-radius: 10px !important;
|
448 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
449 |
}
|
450 |
</style>
|
451 |
""", unsafe_allow_html=True)
|
452 |
|
453 |
st.markdown("""
|
454 |
<style>
|
455 |
-
/* تغییر رنگ متن placeholder به خاکستری */
|
456 |
textarea::placeholder {
|
457 |
-
color: #ffffff !important;
|
458 |
-
opacity: 1 !important;
|
459 |
}
|
460 |
-
/* تغییر رنگ متن داخل چت اینپوت به خاکستری */
|
461 |
textarea {
|
462 |
-
color: #ffffff !important;
|
463 |
border-radius: 10px !important;
|
464 |
padding: 10px !important;
|
465 |
}
|
@@ -467,7 +431,6 @@ textarea {
|
|
467 |
""", unsafe_allow_html=True)
|
468 |
|
469 |
|
470 |
-
# استایلها برای چرخش و پیام در حال فکر کردن
|
471 |
st.markdown("""
|
472 |
<style>
|
473 |
.thinking-message {
|
@@ -481,7 +444,7 @@ st.markdown("""
|
|
481 |
}
|
482 |
.spinner {
|
483 |
border: 4px solid #f3f3f3;
|
484 |
-
border-top: 4px solid #4b6d3d;
|
485 |
border-radius: 50%;
|
486 |
width: 20px;
|
487 |
height: 20px;
|
@@ -504,15 +467,12 @@ from rapidfuzz import fuzz
|
|
504 |
from langchain.schema import SystemMessage, HumanMessage
|
505 |
from langchain.chat_models import ChatOpenAI
|
506 |
|
507 |
-
# تنظیمات
|
508 |
folder_path = '46'
|
509 |
normalizer = Normalizer()
|
510 |
|
511 |
-
# حافظه گفتگو
|
512 |
if "chat_history" not in st.session_state:
|
513 |
st.session_state.chat_history = []
|
514 |
|
515 |
-
# بارگذاری اسناد
|
516 |
@st.cache_data(show_spinner="در حال بارگذاری اسناد...")
|
517 |
def load_and_process_documents(path):
|
518 |
def process_docx(filename):
|
@@ -535,14 +495,12 @@ def load_and_process_documents(path):
|
|
535 |
|
536 |
doc_texts = load_and_process_documents(folder_path)
|
537 |
|
538 |
-
# کلمات توقف
|
539 |
stop_words = [
|
540 |
"است", "و", "با", "که", "در", "از", "برای", "به", "بر", "تا", "این", "آن", "یک", "کدام", "کجا", "هم", "همه",
|
541 |
"یا", "همچنین", "می", "باید", "شود", "شد", "گفت", "گویا", "داشت", "داشتن", "کنند", "کنیم",
|
542 |
"کرد", "کردن", "نیز", "اگر", "ای", "اینکه", "نه", "باشید", "باشم", "باشی", "در حالی که", "مگر", "چرا"
|
543 |
]
|
544 |
|
545 |
-
# توابع کمکی
|
546 |
def remove_stop_words(text, stop_words):
|
547 |
words = text.split()
|
548 |
return " ".join([word for word in words if word not in stop_words])
|
@@ -580,7 +538,6 @@ def remove_stop_words_from_lines(lines, stop_words):
|
|
580 |
cleaned_lines.append(" ".join(cleaned_words))
|
581 |
return cleaned_lines
|
582 |
|
583 |
-
# ورودی کاربر با chat_input
|
584 |
query = st.chat_input("چطور میتونم کمک کنم؟")
|
585 |
|
586 |
if query:
|
@@ -592,7 +549,6 @@ if query:
|
|
592 |
</div>
|
593 |
""", unsafe_allow_html=True)
|
594 |
|
595 |
-
# جستجو در متن اسناد
|
596 |
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=3)
|
597 |
cleaned_closest_lines = remove_stop_words_from_lines(closest_lines, stop_words)
|
598 |
|
@@ -614,10 +570,8 @@ if query:
|
|
614 |
else:
|
615 |
final_answer = "❗ هیچ خط مرتبطی با سؤال پیدا نشد."
|
616 |
|
617 |
-
# پاک کردن وضعیت در حال فکر کردن
|
618 |
thinking.empty()
|
619 |
|
620 |
-
# ذخیره و نمایش پاسخ
|
621 |
st.session_state.chat_history.append(("🧑", query))
|
622 |
st.session_state.chat_history.append(("🤖", final_answer))
|
623 |
|
@@ -637,7 +591,6 @@ st.markdown("""
|
|
637 |
</style>
|
638 |
""", unsafe_allow_html=True)
|
639 |
|
640 |
-
# نمایش تاریخچه گفتگو
|
641 |
st.markdown("---")
|
642 |
for sender, message in st.session_state.chat_history:
|
643 |
st.markdown(f'<div class="chat-message"><strong>{sender}</strong>: {message}</div>', unsafe_allow_html=True)
|
|
|
17 |
|
18 |
st.markdown("""
|
19 |
<style>
|
|
|
20 |
.stAppHeader.st-emotion-cache-12fmjuu.e4hpqof0 {
|
21 |
+
background-color: rgba(46,59,46, 0.8) !important;
|
22 |
+
color: #2e3b2e !important;
|
23 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
24 |
+
padding: 20px !important;
|
25 |
+
border-radius: 10px !important;
|
26 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
27 |
}
|
28 |
</style>
|
29 |
""", unsafe_allow_html=True)
|
30 |
st.markdown("""
|
31 |
<style>
|
|
|
32 |
@font-face {
|
33 |
font-family: 'Roboto';
|
34 |
src: url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap') format('woff2');
|
35 |
font-weight: 400;
|
36 |
font-style: normal;
|
37 |
}
|
|
|
38 |
html, body, [class*="css"] {
|
39 |
font-family: 'Roboto', Tahoma, sans-serif !important;
|
40 |
font-weight: 400 !important;
|
|
|
42 |
text-align: right;
|
43 |
ظ color: #ffffff;
|
44 |
}
|
|
|
45 |
.stApp {
|
46 |
background: linear-gradient(to left, #4b5e40, #2e3b2e);
|
47 |
color: #ffffff;
|
48 |
}
|
|
|
49 |
[data-testid="stSidebar"] {
|
50 |
width: 260px !important;
|
51 |
background-color: #1a2b1e;
|
52 |
border: none !important;
|
53 |
padding-top: 20px;
|
54 |
}
|
|
|
55 |
.menu-item {
|
56 |
display: flex;
|
57 |
align-items: center;
|
|
|
63 |
cursor: pointer;
|
64 |
transition: background-color 0.3s ease;
|
65 |
}
|
|
|
66 |
.menu-item:hover {
|
67 |
background-color: #2e3b2e;
|
68 |
color: #b8860b;
|
69 |
}
|
|
|
70 |
.menu-item img {
|
71 |
width: 25px;
|
72 |
height: 25px;
|
73 |
}
|
|
|
74 |
.stButton>button {
|
75 |
background-color: #b8860b !important;
|
76 |
color: #1a2b1e !important;
|
|
|
84 |
width: 100%;
|
85 |
margin: 10px 0;
|
86 |
}
|
|
|
87 |
.stButton>button:hover {
|
88 |
background-color: #8b6508 !important;
|
89 |
transform: translateY(-2px);
|
90 |
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
|
91 |
}
|
|
|
92 |
.header-text {
|
93 |
text-align: center;
|
94 |
margin: 20px 0;
|
|
|
98 |
box-shadow: 0 6px 12px rgba(0,0,0,0.4);
|
99 |
font-family: 'Roboto', Tahoma, sans-serif; /* اضافه شد */
|
100 |
}
|
|
|
101 |
.subtitle {
|
102 |
font-size: 18px;
|
103 |
color: #d4d4d4;
|
104 |
font-weight: 600;
|
105 |
margin-top: 10px;
|
106 |
}
|
|
|
107 |
.chat-message {
|
108 |
flex-wrap: wrap;
|
109 |
background-color: rgba(26, 43, 30, 0.95);
|
|
|
121 |
align-items: center;
|
122 |
gap: 15px;
|
123 |
}
|
|
|
124 |
@keyframes fadeIn {
|
125 |
from { opacity: 0; transform: translateY(10px); }
|
126 |
to { opacity: 1; transform: translateY(0); }
|
127 |
}
|
|
|
128 |
.stTextInput>div>input, .stTextArea textarea {
|
129 |
background-color: rgba(26, 43, 30, 0.95) !important;
|
130 |
border-radius: 10px !important;
|
|
|
135 |
font-size: 16px;
|
136 |
color: #d4d4d4 !important;
|
137 |
}
|
|
|
138 |
hr {
|
139 |
border: 1px solid #b8860b;
|
140 |
margin: 15px 0;
|
141 |
}
|
|
|
142 |
[data-testid="stSidebar"] > div {
|
143 |
border: none !important;
|
144 |
}
|
|
|
146 |
""", unsafe_allow_html=True)
|
147 |
|
148 |
|
|
|
149 |
if "authenticated" not in st.session_state:
|
150 |
st.session_state.authenticated = False
|
151 |
|
|
|
164 |
""", unsafe_allow_html=True)
|
165 |
st.markdown("""
|
166 |
<style>
|
|
|
167 |
html, body, [class*="css"] {
|
168 |
font-family: 'Vazir', sans-serif;
|
169 |
}
|
|
|
170 |
label {
|
171 |
font-size: 20px !important;
|
172 |
color: #ffffff !important;
|
|
|
174 |
margin-bottom: 10px !important;
|
175 |
display: block;
|
176 |
}
|
|
|
177 |
input[type="text"],
|
178 |
input[type="password"],
|
179 |
input[type="text"]:focus,
|
|
|
240 |
""", unsafe_allow_html=True)
|
241 |
st.stop()
|
242 |
|
|
|
243 |
with st.sidebar:
|
244 |
st.image("log.png", use_container_width=True)
|
245 |
|
|
|
275 |
|
276 |
st.markdown("""
|
277 |
<style>
|
|
|
278 |
.header-text {
|
279 |
text-align: center;
|
280 |
margin: 50px 0;
|
281 |
+
background: #2e3b2e;
|
282 |
padding: 60px 30px;
|
283 |
border-radius: 25px;
|
284 |
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.8); /* سایه بیشتر */
|
|
|
287 |
background-position: center;
|
288 |
position: relative;
|
289 |
}
|
|
|
290 |
@keyframes fadeIn {
|
291 |
0% { opacity: 0; transform: translateY(30px); }
|
292 |
100% { opacity: 1; transform: translateY(0); }
|
|
|
295 |
0% { transform: translateX(-50%); opacity: 0; }
|
296 |
100% { transform: translateX(0); opacity: 1; }
|
297 |
}
|
|
|
298 |
.header-text h1 {
|
299 |
font-family: 'Vazir', sans-serif;
|
300 |
font-size: 62px;
|
301 |
+
color: #d89b00;
|
302 |
margin: 0;
|
303 |
font-weight: 900;
|
304 |
letter-spacing: 4px;
|
305 |
+
text-shadow: 4px 4px 15px rgba(0, 0, 0, 0.9);
|
306 |
+
transform: scale(1.08);
|
307 |
animation: glow 2s ease-in-out infinite alternate;
|
308 |
}
|
|
|
309 |
.subtitle {
|
310 |
font-family: 'Vazir', sans-serif;
|
311 |
font-size: 24px;
|
|
|
313 |
font-weight: 700;
|
314 |
margin-top: 15px;
|
315 |
letter-spacing: 2px;
|
316 |
+
text-shadow: 3px 3px 10px rgba(0,0,0,0.8);
|
317 |
animation: fadeInSubtitle 2s ease-in-out;
|
318 |
}
|
|
|
319 |
@keyframes fadeInSubtitle {
|
320 |
0% { opacity: 0; transform: translateY(20px); }
|
321 |
100% { opacity: 1; transform: translateY(0); }
|
322 |
}
|
|
|
323 |
.stButton>button {
|
324 |
+
background-color: #e67e22 !important;
|
325 |
color: #4b5320 !important;
|
326 |
font-family: 'Vazir', sans-serif;
|
327 |
font-weight: 700 !important;
|
|
|
339 |
transform: translateY(-4px);
|
340 |
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
|
341 |
}
|
|
|
342 |
.stApp {
|
343 |
+
background: #2e3b2e;
|
344 |
color: white;
|
345 |
font-family: 'Vazir', sans-serif;
|
346 |
}
|
|
|
351 |
</div>
|
352 |
""", unsafe_allow_html=True)
|
353 |
|
|
|
354 |
llm = ChatOpenAI(
|
355 |
base_url="https://api.together.xyz/v1",
|
356 |
api_key='0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979',
|
|
|
365 |
|
366 |
# llm = pipeline("text-generation", model=model_name)
|
367 |
|
|
|
368 |
st.markdown("""
|
369 |
<style>
|
|
|
370 |
.st-emotion-cache-128upt6.eht7o1d3 {
|
371 |
+
background-color: rgba(46,59,46, 0.8) !important;
|
372 |
+
border-radius: 10px !important;
|
373 |
+
color: #d4d4d4 !important;
|
374 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
375 |
+
padding: 15px !important;
|
376 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
377 |
}
|
378 |
</style>
|
379 |
""", unsafe_allow_html=True)
|
|
|
393 |
|
394 |
st.markdown("""
|
395 |
<style>
|
|
|
396 |
.st-emotion-cache-yd4u6l.e1togvvn1 {
|
397 |
+
background-color: rgba(106, 127, 83, 0.8) !important;
|
398 |
+
border-radius: 10px !important;
|
399 |
+
color: #d4d4d4 !important;
|
400 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
401 |
+
padding: 15px !important;
|
402 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
403 |
}
|
404 |
</style>
|
405 |
""", unsafe_allow_html=True)
|
406 |
st.markdown("""
|
407 |
<style>
|
|
|
408 |
.stAppHeader.st-emotion-cache-12fmjuu.e4hpqof0 {
|
409 |
+
background-color: rgba(42, 55, 39, 0.9) !important;
|
410 |
+
color: #d4d4d4 !important;
|
411 |
font-family: 'Vazirmatn', Tahoma, sans-serif !important;
|
412 |
+
padding: 20px !important;
|
413 |
+
border-radius: 10px !important;
|
414 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
|
415 |
}
|
416 |
</style>
|
417 |
""", unsafe_allow_html=True)
|
418 |
|
419 |
st.markdown("""
|
420 |
<style>
|
|
|
421 |
textarea::placeholder {
|
422 |
+
color: #ffffff !important;
|
423 |
+
opacity: 1 !important;
|
424 |
}
|
|
|
425 |
textarea {
|
426 |
+
color: #ffffff !important;
|
427 |
border-radius: 10px !important;
|
428 |
padding: 10px !important;
|
429 |
}
|
|
|
431 |
""", unsafe_allow_html=True)
|
432 |
|
433 |
|
|
|
434 |
st.markdown("""
|
435 |
<style>
|
436 |
.thinking-message {
|
|
|
444 |
}
|
445 |
.spinner {
|
446 |
border: 4px solid #f3f3f3;
|
447 |
+
border-top: 4px solid #4b6d3d;
|
448 |
border-radius: 50%;
|
449 |
width: 20px;
|
450 |
height: 20px;
|
|
|
467 |
from langchain.schema import SystemMessage, HumanMessage
|
468 |
from langchain.chat_models import ChatOpenAI
|
469 |
|
|
|
470 |
folder_path = '46'
|
471 |
normalizer = Normalizer()
|
472 |
|
|
|
473 |
if "chat_history" not in st.session_state:
|
474 |
st.session_state.chat_history = []
|
475 |
|
|
|
476 |
@st.cache_data(show_spinner="در حال بارگذاری اسناد...")
|
477 |
def load_and_process_documents(path):
|
478 |
def process_docx(filename):
|
|
|
495 |
|
496 |
doc_texts = load_and_process_documents(folder_path)
|
497 |
|
|
|
498 |
stop_words = [
|
499 |
"است", "و", "با", "که", "در", "از", "برای", "به", "بر", "تا", "این", "آن", "یک", "کدام", "کجا", "هم", "همه",
|
500 |
"یا", "همچنین", "می", "باید", "شود", "شد", "گفت", "گویا", "داشت", "داشتن", "کنند", "کنیم",
|
501 |
"کرد", "کردن", "نیز", "اگر", "ای", "اینکه", "نه", "باشید", "باشم", "باشی", "در حالی که", "مگر", "چرا"
|
502 |
]
|
503 |
|
|
|
504 |
def remove_stop_words(text, stop_words):
|
505 |
words = text.split()
|
506 |
return " ".join([word for word in words if word not in stop_words])
|
|
|
538 |
cleaned_lines.append(" ".join(cleaned_words))
|
539 |
return cleaned_lines
|
540 |
|
|
|
541 |
query = st.chat_input("چطور میتونم کمک کنم؟")
|
542 |
|
543 |
if query:
|
|
|
549 |
</div>
|
550 |
""", unsafe_allow_html=True)
|
551 |
|
|
|
552 |
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=3)
|
553 |
cleaned_closest_lines = remove_stop_words_from_lines(closest_lines, stop_words)
|
554 |
|
|
|
570 |
else:
|
571 |
final_answer = "❗ هیچ خط مرتبطی با سؤال پیدا نشد."
|
572 |
|
|
|
573 |
thinking.empty()
|
574 |
|
|
|
575 |
st.session_state.chat_history.append(("🧑", query))
|
576 |
st.session_state.chat_history.append(("🤖", final_answer))
|
577 |
|
|
|
591 |
</style>
|
592 |
""", unsafe_allow_html=True)
|
593 |
|
|
|
594 |
st.markdown("---")
|
595 |
for sender, message in st.session_state.chat_history:
|
596 |
st.markdown(f'<div class="chat-message"><strong>{sender}</strong>: {message}</div>', unsafe_allow_html=True)
|