File size: 2,283 Bytes
ec8033f
 
 
5a41c9b
 
 
 
 
 
ec8033f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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)