Ines1994 commited on
Commit
ee7678b
·
verified ·
1 Parent(s): 2e62f2c

Upload 2 files

Browse files
Files changed (2) hide show
  1. agentic_rag.py +3 -3
  2. app.py +3 -0
agentic_rag.py CHANGED
@@ -126,7 +126,7 @@ def tool_search_db(engine, query: str):
126
  if not top:
127
  return "لم أجد معلومات كافية في قاعدة البيانات.", []
128
  context = "\n\n".join([f"[{i+1}] {c['content']}" for i, c in enumerate(top)])
129
- sources = [{"url": c.get("url", ""), "page_name": c.get("page_name", "")} for c in top]
130
  return context, sources
131
  except Exception as e:
132
  return f"خطأ في البحث: {e}", []
@@ -143,7 +143,7 @@ def tool_get_concours_page(concours_type: str):
143
  tag.decompose()
144
  text = soup.get_text(" ", strip=True)
145
  # نجيب أهم جزء — أول 4000 حرف
146
- return f"[من {url}]\n\n{text[:4000]}", [{"url": url, "page_name": concours_type}]
147
  except Exception as e:
148
  return f"خطأ في جلب الصفحة: {e}", []
149
 
@@ -177,7 +177,7 @@ def tool_summarize_url(url: str):
177
  for tag in soup(["script", "style", "nav", "footer", "header"]):
178
  tag.decompose()
179
  text = soup.get_text(" ", strip=True)
180
- return text[:3000], [{"url": url, "page_name": "رابط مقال"}]
181
  except Exception as e:
182
  return f"خطأ في جلب الرابط: {e}", []
183
 
 
126
  if not top:
127
  return "لم أجد معلومات كافية في قاعدة البيانات.", []
128
  context = "\n\n".join([f"[{i+1}] {c['content']}" for i, c in enumerate(top)])
129
+ sources = [{"url": c.get("url", ""), "page_name": c.get("page_name", ""), "content": c.get("content", "")} for c in top]
130
  return context, sources
131
  except Exception as e:
132
  return f"خطأ في البحث: {e}", []
 
143
  tag.decompose()
144
  text = soup.get_text(" ", strip=True)
145
  # نجيب أهم جزء — أول 4000 حرف
146
+ return f"[من {url}]\n\n{text[:4000]}", [{"url": url, "page_name": concours_type, "content": text[:800] + "..."}]
147
  except Exception as e:
148
  return f"خطأ في جلب الصفحة: {e}", []
149
 
 
177
  for tag in soup(["script", "style", "nav", "footer", "header"]):
178
  tag.decompose()
179
  text = soup.get_text(" ", strip=True)
180
+ return text[:3000], [{"url": url, "page_name": "رابط مقال", "content": text[:800] + "..."}]
181
  except Exception as e:
182
  return f"خطأ في جلب الرابط: {e}", []
183
 
app.py CHANGED
@@ -242,9 +242,12 @@ def main():
242
  for i, src in enumerate(sources):
243
  url = src.get("url", "")
244
  page_name = src.get("page_name", "")
 
245
  if url:
246
  with st.expander(f"المصدر [{i+1}]: {page_name}"):
247
  st.markdown(f"[{url}]({url})")
 
 
248
  else:
249
  info_msg = "ستظهر الأداة المستخدمة والمصادر هنا" if is_ar else "L'outil utilisé et les sources apparaîtront ici"
250
  st.info(info_msg)
 
242
  for i, src in enumerate(sources):
243
  url = src.get("url", "")
244
  page_name = src.get("page_name", "")
245
+ content = src.get("content", "")
246
  if url:
247
  with st.expander(f"المصدر [{i+1}]: {page_name}"):
248
  st.markdown(f"[{url}]({url})")
249
+ if content:
250
+ st.text_area("النص المستخرج", content, height=120, disabled=True, key=f"src_{i}_{len(st.session_state.chat_messages)}")
251
  else:
252
  info_msg = "ستظهر الأداة المستخدمة والمصادر هنا" if is_ar else "L'outil utilisé et les sources apparaîtront ici"
253
  st.info(info_msg)