Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files65 unmodified lines6667686970717273747576777879808182838485868788899091929394959697989965 unmodified linesst.error(f"Error scraping RBI master circulars list: {e}")return []def fetch_circular_detail_text(detail_url, link_type):try:resp = requests.get(detail_url, timeout=20)resp.raise_for_status()if link_type == "pdf":extracted_text = ""with pdfplumber.open(BytesIO(resp.content)) as pdf:for page in pdf.pages:page_text = page.extract_text()if page_text:extracted_text += page_text + "\n"return extracted_textelse:soup = BeautifulSoup(resp.text, "html.parser")# Grab all text inside likely content containers (div, main, section, p)content_blocks = []for tag in ['main', 'section', 'div', 'p']:for elem in soup.find_all(tag):txt = elem.get_text(separator='\n').strip()if txt and len(txt) > 50:content_blocks.append(txt)# Fallback: All text if no blocks foundextract = "\n\n".join(content_blocks) if content_blocks else soup.get_text(separator='\n')clean_text = "\n".join([line.strip() for line in extract.splitlines() if line.strip()])return clean_textexcept Exception as e:st.error(f"Error extracting circular: {e}")return ""# ========== Streamlit UI ==========st.title("Automated RBI Master Circular Summarizer (PDF + HTML)")65 unmodified lines6667686970717273747576777879808182838485868788899091929394959697989910010165 unmodified linesst.error(f"Error scraping RBI master circulars list: {e}")return []def get_master_circular_candidates():index_url = "https://website.rbi.org.in/web/rbi/notifications/master-circulars"base_url = "https://website.rbi.org.in"try:resp = requests.get(index_url, timeout=20)resp.raise_for_status()soup = BeautifulSoup(resp.text, "html.parser")candidates = []for a in soup.find_all("a", href=True):href = a["href"]link_text = a.get_text().strip()# Normalizefull_url = requests.compat.urljoin(base_url, href)# PDF detection (actual PDF or common 'documents/d/rbi/')if ".pdf" in href.lower() or "/documents/d/rbi/" in href:candidates.append({'url': full_url, 'text': link_text, 'type': 'pdf'})# HTML notification detection (the -/notifications/ pattern)elif (href.startswith("/web/rbi/-/notifications/")or "notifications/master-circular" in href):candidates.append({'url': full_url, 'text': link_text, 'type': 'html'})# Add other patterns if you see more real circular HTML linksif not candidates:st.error("No master circular links found.")return candidatesexcept Exception as e:st.error(f"Error scraping RBI master circulars list: {e}")return []# ========== Streamlit UI ==========st.title("Automated RBI Master Circular Summarizer (PDF + HTML)")
streamlit_app.py+27-25