Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,6 @@ st.set_page_config(page_title="رزم یار ارتش", page_icon="🪖", layout
|
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap');
|
22 |
-
|
23 |
html, body, [class*="css"] {
|
24 |
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
25 |
direction: rtl;
|
@@ -215,8 +214,8 @@ def get_csv_index(csv_file):
|
|
215 |
|
216 |
# تقسیم متنهای طولانی به بخشهای کوچکتر
|
217 |
text_splitter = RecursiveCharacterTextSplitter(
|
218 |
-
chunk_size=
|
219 |
-
chunk_overlap=
|
220 |
length_function=len,
|
221 |
separators=["\n\n", "\n", " ", ""]
|
222 |
)
|
@@ -227,7 +226,7 @@ def get_csv_index(csv_file):
|
|
227 |
|
228 |
# ایجاد embeddings
|
229 |
embeddings = TogetherEmbeddings(
|
230 |
-
model_name="togethercomputer/m2-bert-80M-
|
231 |
api_key="0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979"
|
232 |
)
|
233 |
|
@@ -249,7 +248,7 @@ csv_file_path = 'output (1).csv'
|
|
249 |
try:
|
250 |
# ساخت ایندکس
|
251 |
csv_index = get_csv_index(csv_file_path)
|
252 |
-
|
253 |
except Exception as e:
|
254 |
st.error(f"خطا در ساخت ایندکس: {str(e)}")
|
255 |
|
@@ -259,7 +258,7 @@ except Exception as e:
|
|
259 |
llm = ChatOpenAI(
|
260 |
base_url="https://api.together.xyz/v1",
|
261 |
api_key='0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979',
|
262 |
-
model="togethercomputer/m2-bert-80M-
|
263 |
)
|
264 |
|
265 |
chain = RetrievalQA.from_chain_type(
|
@@ -291,7 +290,7 @@ if st.session_state.pending_prompt:
|
|
291 |
thinking = st.empty()
|
292 |
thinking.markdown("🤖 در حال فکر کردن...")
|
293 |
|
294 |
-
response = chain.run(f'پاسخ را فقط به زبان فارسی جواب بده به هیچ عنوان از زبان غیر از فارسی در پاسخ استفاده
|
295 |
answer = response.split("Helpful Answer:")[-1].strip() if "Helpful Answer:" in response else response.strip()
|
296 |
if not answer:
|
297 |
answer = "متأسفم، اطلاعات دقیقی در این مورد ندارم."
|
|
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap');
|
|
|
22 |
html, body, [class*="css"] {
|
23 |
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
24 |
direction: rtl;
|
|
|
214 |
|
215 |
# تقسیم متنهای طولانی به بخشهای کوچکتر
|
216 |
text_splitter = RecursiveCharacterTextSplitter(
|
217 |
+
chunk_size=300,
|
218 |
+
chunk_overlap=50,
|
219 |
length_function=len,
|
220 |
separators=["\n\n", "\n", " ", ""]
|
221 |
)
|
|
|
226 |
|
227 |
# ایجاد embeddings
|
228 |
embeddings = TogetherEmbeddings(
|
229 |
+
model_name="togethercomputer/m2-bert-80M-8k-retrieval",
|
230 |
api_key="0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979"
|
231 |
)
|
232 |
|
|
|
248 |
try:
|
249 |
# ساخت ایندکس
|
250 |
csv_index = get_csv_index(csv_file_path)
|
251 |
+
st.success("ایندکس فایل CSV با موفقیت ساخته شد!")
|
252 |
except Exception as e:
|
253 |
st.error(f"خطا در ساخت ایندکس: {str(e)}")
|
254 |
|
|
|
258 |
llm = ChatOpenAI(
|
259 |
base_url="https://api.together.xyz/v1",
|
260 |
api_key='0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979',
|
261 |
+
model="togethercomputer/m2-bert-80M-8k-retrieval"
|
262 |
)
|
263 |
|
264 |
chain = RetrievalQA.from_chain_type(
|
|
|
290 |
thinking = st.empty()
|
291 |
thinking.markdown("🤖 در حال فکر کردن...")
|
292 |
|
293 |
+
response = chain.run(f'پاسخ را فقط به زبان فارسی جواب بده و به هیچ عنوان از زبان غیر از فارسی در پاسخ استفاده نکن: {st.session_state.pending_prompt}')
|
294 |
answer = response.split("Helpful Answer:")[-1].strip() if "Helpful Answer:" in response else response.strip()
|
295 |
if not answer:
|
296 |
answer = "متأسفم، اطلاعات دقیقی در این مورد ندارم."
|