# app/main.py import streamlit as st from ocr_extractor import extract_text_from_pdf from classifier import classify_bill, extract_fields from recommender import recommend_plans from visualisation import show_comparison_chart from agent_chain import agentic_reasoning st.set_page_config(page_title="Telco Bill Recommender", layout="wide") st.title("📄 Telco Bill Scanner & Plan Recommender") # Upload Bill uploaded_file = st.file_uploader("Upload your Telco Bill (PDF or JSON)", type=["pdf", "json"]) if uploaded_file: st.success("Bill uploaded successfully!") # Step 0: OCR Extraction for PDFs if uploaded_file.name.endswith(".pdf"): st.subheader("Step 0: OCR Extraction") extracted_text = extract_text_from_pdf(uploaded_file) st.text_area("Extracted Text (Preview)", extracted_text[:1000]) # Extract structured fields from OCR text fields = extract_fields(extracted_text) else: extracted_text = None fields = None # Step 1: Customer Type Classification st.subheader("Step 1: Customer Type Identification") if fields: customer_type, details = classify_bill(None, fields) else: customer_type, details = classify_bill(uploaded_file) st.write(f"**Detected Type:** {customer_type}") st.json(details) # Fallback to Agentic AI if classification uncertain if customer_type == "Unknown": st.warning("Classification uncertain. Using Agentic AI fallback reasoning...") # Use extracted text if available; else read file as text if extracted_text: agent_input = extracted_text else: try: agent_input = uploaded_file.read().decode("utf-8", errors="ignore") except: agent_input = "Could not read file." customer_type = agentic_reasoning(agent_input) st.write(f"**Agentic AI suggests:** {customer_type}") # Step 2: Plan Recommendation st.subheader("Step 2: Plan Recommendations") recommendations = recommend_plans(uploaded_file, customer_type) st.table(recommendations) # Step 3: Visualisation of Savings st.subheader("Step 3: Usage & Cost Comparison") show_comparison_chart(uploaded_file, recommendations)