Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,85 @@ from sentence_transformers import SentenceTransformer
|
|
18 |
import numpy as np
|
19 |
|
20 |
# ----------------- تنظیمات صفحه -----------------
|
21 |
-
st.set_page_config(page_title="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# ----------------- بارگذاری مدل FarsiBERT -----------------
|
24 |
# model_name = "HooshvareLab/bert-fa-zwnj-base"
|
@@ -44,7 +122,7 @@ def build_pdf_index():
|
|
44 |
|
45 |
documents = [LangchainDocument(page_content=t) for t in texts]
|
46 |
|
47 |
-
sentence_model = SentenceTransformer('
|
48 |
|
49 |
progress_bar = st.progress(0)
|
50 |
total_docs = len(documents)
|
@@ -59,6 +137,8 @@ def build_pdf_index():
|
|
59 |
embeddings.extend(batch_embeddings)
|
60 |
|
61 |
progress_bar.progress(min((i + batch_size) / total_docs, 1.0))
|
|
|
|
|
62 |
|
63 |
embeddings = np.array(embeddings)
|
64 |
|
@@ -81,7 +161,7 @@ class SimpleRetriever(BaseRetriever):
|
|
81 |
|
82 |
def _get_relevant_documents(self, query: str) -> List[Document]:
|
83 |
# فقط از sentence_model استفاده میکنیم
|
84 |
-
sentence_model = SentenceTransformer('
|
85 |
query_embedding = sentence_model.encode(query, convert_to_numpy=True)
|
86 |
|
87 |
similarities = []
|
|
|
18 |
import numpy as np
|
19 |
|
20 |
# ----------------- تنظیمات صفحه -----------------
|
21 |
+
st.set_page_config(page_title="چت بات توانا", page_icon="🪖", layout="wide")
|
22 |
+
|
23 |
+
st.markdown("""
|
24 |
+
<style>
|
25 |
+
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap');
|
26 |
+
html, body, [class*="css"] {
|
27 |
+
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
28 |
+
direction: rtl;
|
29 |
+
text-align: right;
|
30 |
+
}
|
31 |
+
.stApp {
|
32 |
+
background: url("./military_bg.jpeg") no-repeat center center fixed;
|
33 |
+
background-size: cover;
|
34 |
+
backdrop-filter: blur(2px);
|
35 |
+
}
|
36 |
+
.stChatMessage {
|
37 |
+
background-color: rgba(255,255,255,0.8);
|
38 |
+
border: 1px solid #4e8a3e;
|
39 |
+
border-radius: 12px;
|
40 |
+
padding: 16px;
|
41 |
+
margin-bottom: 15px;
|
42 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
|
43 |
+
animation: fadeIn 0.4s ease-in-out;
|
44 |
+
}
|
45 |
+
.stTextInput > div > input, .stTextArea textarea {
|
46 |
+
background-color: rgba(255,255,255,0.9) !important;
|
47 |
+
border-radius: 8px !important;
|
48 |
+
direction: rtl;
|
49 |
+
text-align: right;
|
50 |
+
font-family: 'Vazirmatn', Tahoma;
|
51 |
+
}
|
52 |
+
.stButton>button {
|
53 |
+
background-color: #4e8a3e !important;
|
54 |
+
color: white !important;
|
55 |
+
font-weight: bold;
|
56 |
+
border-radius: 10px;
|
57 |
+
padding: 8px 20px;
|
58 |
+
transition: 0.3s;
|
59 |
+
}
|
60 |
+
.stButton>button:hover {
|
61 |
+
background-color: #3c6d30 !important;
|
62 |
+
}
|
63 |
+
.header-text {
|
64 |
+
text-align: center;
|
65 |
+
margin-top: 20px;
|
66 |
+
margin-bottom: 40px;
|
67 |
+
background-color: rgba(255, 255, 255, 0.75);
|
68 |
+
padding: 20px;
|
69 |
+
border-radius: 20px;
|
70 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
71 |
+
}
|
72 |
+
.header-text h1 {
|
73 |
+
font-size: 42px;
|
74 |
+
color: #2c3e50;
|
75 |
+
margin: 0;
|
76 |
+
font-weight: bold;
|
77 |
+
}
|
78 |
+
.subtitle {
|
79 |
+
font-size: 18px;
|
80 |
+
color: #34495e;
|
81 |
+
margin-top: 8px;
|
82 |
+
}
|
83 |
+
@keyframes fadeIn {
|
84 |
+
from { opacity: 0; transform: translateY(10px); }
|
85 |
+
to { opacity: 1; transform: translateY(0); }
|
86 |
+
}
|
87 |
+
</style>
|
88 |
+
""", unsafe_allow_html=True)
|
89 |
+
|
90 |
+
col1, col2, col3 = st.columns([1, 1, 1])
|
91 |
+
with col2:
|
92 |
+
st.image("army.png", width=240)
|
93 |
+
|
94 |
+
st.markdown("""
|
95 |
+
<div class="header-text">
|
96 |
+
<h1>چت بات توانا</h1>
|
97 |
+
<div class="subtitle">دستیار هوشمند برای تصمیمگیری در میدان نبرد</div>
|
98 |
+
</div>
|
99 |
+
""", unsafe_allow_html=True)
|
100 |
|
101 |
# ----------------- بارگذاری مدل FarsiBERT -----------------
|
102 |
# model_name = "HooshvareLab/bert-fa-zwnj-base"
|
|
|
122 |
|
123 |
documents = [LangchainDocument(page_content=t) for t in texts]
|
124 |
|
125 |
+
sentence_model = SentenceTransformer('HooshvareLab/bert-fa-zwnj-base')
|
126 |
|
127 |
progress_bar = st.progress(0)
|
128 |
total_docs = len(documents)
|
|
|
137 |
embeddings.extend(batch_embeddings)
|
138 |
|
139 |
progress_bar.progress(min((i + batch_size) / total_docs, 1.0))
|
140 |
+
time.sleep(5)
|
141 |
+
progress_bar.empty()
|
142 |
|
143 |
embeddings = np.array(embeddings)
|
144 |
|
|
|
161 |
|
162 |
def _get_relevant_documents(self, query: str) -> List[Document]:
|
163 |
# فقط از sentence_model استفاده میکنیم
|
164 |
+
sentence_model = SentenceTransformer('HooshvareLab/bert-fa-zwnj-base')
|
165 |
query_embedding = sentence_model.encode(query, convert_to_numpy=True)
|
166 |
|
167 |
similarities = []
|