File size: 2,678 Bytes
ff2cc46
 
 
 
 
 
928873d
ff2cc46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
928873d
ff2cc46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
928873d
 
 
 
 
 
 
 
 
ff2cc46
928873d
ff2cc46
928873d
ff2cc46
 
 
 
 
 
 
 
 
 
 
 
 
 
928873d
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
69
70
# streamlit_app.py
import streamlit as st
import requests
import json
from PIL import Image
import io
import base64

API_URL = "http://localhost:7860/process-image"  # Change if hosted elsewhere

st.set_page_config(page_title="Flowchart to English", layout="wide")
st.title("πŸ“„ Flowchart to Plain English")

# Debug mode switch
debug_mode = st.toggle("πŸ”§ Show Debug Info", value=False)

uploaded_file = st.file_uploader("Upload a flowchart image", type=["png", "jpg", "jpeg"])

if uploaded_file:
    # Resize image for smaller canvas
    image = Image.open(uploaded_file)
    max_width = 600
    ratio = max_width / float(image.size[0])
    new_height = int((float(image.size[1]) * float(ratio)))
    resized_image = image.resize((max_width, new_height))
    st.image(resized_image, caption="πŸ“€ Uploaded Image", use_container_width=False)

    if st.button("πŸ” Analyze Flowchart"):
        progress = st.progress(0, text="Sending image to backend...")

        try:
            response = requests.post(
                API_URL,
                files={"file": uploaded_file.getvalue()},
                data={"debug": str(debug_mode).lower()}
            )
            progress.progress(50, text="Processing detection, OCR, and reasoning...")

            if response.status_code == 200:
                data = response.json()
                progress.progress(80, text="Generating explanation using LLM...")

                # Optional: Visualize bounding boxes
                if debug_mode and data.get("yolo_vis"):
                    st.markdown("### πŸ–ΌοΈ YOLO Debug Bounding Boxes")
                    vis_bytes = base64.b64decode(data["yolo_vis"])
                    vis_img = Image.open(io.BytesIO(vis_bytes))
                    st.image(vis_img, caption="YOLO Detected Boxes", use_container_width=True)

                # Optional: show logs
                if debug_mode and "debug" in data:
                    st.markdown("### πŸ§ͺ Debug Pipeline Info")
                    st.code(data["debug"], language="markdown")

                # Display results in 2 columns
                col1, col2 = st.columns(2)
                with col1:
                    st.subheader("🧠 Flowchart JSON")
                    st.json(data["flowchart"])
                with col2:
                    st.subheader("πŸ“ English Summary")
                    st.markdown(data["summary"])

                progress.progress(100, text="Done!")
            else:
                st.error(f"Something went wrong: {response.status_code}")
        except Exception as e:
            st.error(f"An error occurred: {e}")
else:
    st.info("Upload a flowchart image to begin.")