Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,6 @@ llm = ChatOpenAI(
|
|
10 |
api_key='0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979',
|
11 |
model="deepseek-ai/DeepSeek-R1"
|
12 |
)
|
13 |
-
def rewrite_answer_with_llm(answer, user_input):
|
14 |
-
prompt = f"پاسخی که باید بازنویسی شود:\n{answer}\n\nلطفاً این پاسخ را با در نظر گرفتن محتوای سوال زیر و لحن آن بازنویسی کن:\n\nسوال: {user_input}"
|
15 |
-
|
16 |
-
response = llm([{"role": "system", "content": "You are a helpful assistant."},
|
17 |
-
{"role": "user", "content": prompt}])
|
18 |
-
|
19 |
-
return response.strip()
|
20 |
|
21 |
folder_path = '46'
|
22 |
texts = []
|
@@ -45,21 +38,27 @@ if query:
|
|
45 |
found = False
|
46 |
for idx, sentence in enumerate(all_sentences):
|
47 |
if query in sentence:
|
48 |
-
st.success("✅ جمله یافت شد:")
|
49 |
-
st.write(sentence)
|
50 |
|
51 |
next_sentences = []
|
52 |
-
st.markdown("📌 پنج جمله بعدی:")
|
53 |
for i in range(1, 6):
|
54 |
if idx + i < len(all_sentences):
|
55 |
-
st.write(all_sentences[idx + i])
|
56 |
next_sentences.append(all_sentences[idx + i])
|
57 |
|
58 |
-
# ↪️ آمادهسازی برای
|
59 |
total_text = sentence + " " + " ".join(next_sentences)
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
found = True
|
65 |
break
|
|
|
10 |
api_key='0291f33aee03412a47fa5d8e562e515182dcc5d9aac5a7fb5eefdd1759005979',
|
11 |
model="deepseek-ai/DeepSeek-R1"
|
12 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
folder_path = '46'
|
15 |
texts = []
|
|
|
38 |
found = False
|
39 |
for idx, sentence in enumerate(all_sentences):
|
40 |
if query in sentence:
|
|
|
|
|
41 |
|
42 |
next_sentences = []
|
|
|
43 |
for i in range(1, 6):
|
44 |
if idx + i < len(all_sentences):
|
|
|
45 |
next_sentences.append(all_sentences[idx + i])
|
46 |
|
47 |
+
# ↪️ آمادهسازی پرامپت برای ارسال به مدل
|
48 |
total_text = sentence + " " + " ".join(next_sentences)
|
49 |
+
prompt = f"پاسخی که باید بازنویسی شود:\n{total_text}\n\nلطفاً این پاسخ را با در نظر گرفتن محتوای سوال زیر و لحن آن بازنویسی کن:\n\nسوال: {query}"
|
50 |
+
|
51 |
+
# ارسال پرامپت به مدل و دریافت پاسخ
|
52 |
+
response = llm([{"role": "system", "content": "You are a helpful assistant."},
|
53 |
+
{"role": "user", "content": prompt}])
|
54 |
+
|
55 |
+
# استخراج پاسخ مدل
|
56 |
+
if isinstance(response, dict) and 'choices' in response:
|
57 |
+
rewritten = response['choices'][0]['message']['content'].strip()
|
58 |
+
st.markdown("🎨 **بازنویسی شده با LLM:**")
|
59 |
+
st.write(rewritten)
|
60 |
+
else:
|
61 |
+
st.warning("پاسخ دریافتی معتبر نیست.")
|
62 |
|
63 |
found = True
|
64 |
break
|