Spaces:
Sleeping
Sleeping
File size: 2,617 Bytes
c20d656 c842ab7 ff2cc46 928873d c842ab7 ff2cc46 c20d656 928873d c842ab7 ff2cc46 c20d656 c842ab7 ff2cc46 c20d656 c842ab7 ff2cc46 c842ab7 c20d656 c842ab7 928873d c842ab7 c20d656 ff2cc46 c842ab7 c20d656 ff2cc46 c20d656 c842ab7 c20d656 c842ab7 ff2cc46 c20d656 c842ab7 928873d c20d656 c842ab7 ff2cc46 c842ab7 c20d656 c842ab7 c20d656 |
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 71 72 73 74 75 76 |
# app.py
import streamlit as st
from PIL import Image
import io
import base64
import os
# Local modules
from yolo_module import run_yolo
from ocr_module import extract_text
from graph_module import map_arrows, build_flowchart_json
from summarizer_module import summarize_flowchart
st.set_page_config(page_title="Flowchart to English", layout="wide")
st.title("π Flowchart to Plain English")
# Enable debug mode
debug_mode = st.toggle("π§ Show Debug Info", value=False)
# Upload image
uploaded_file = st.file_uploader("Upload a flowchart image", type=["png", "jpg", "jpeg"])
if uploaded_file:
image = Image.open(uploaded_file).convert("RGB")
# Show resized preview
max_width = 600
ratio = max_width / float(image.size[0])
resized_image = image.resize((max_width, int(image.size[1] * ratio)))
st.image(resized_image, caption="π€ Uploaded Image", use_container_width=False)
if st.button("π Analyze Flowchart"):
progress = st.progress(0, text="Detecting boxes and arrows...")
results, arrows, vis_debug = run_yolo(image)
progress.progress(25, text="Running OCR...")
debug_log = []
debug_log.append(f"π¦ Detected {len(results)} boxes")
debug_log.append(f"β‘οΈ Detected {len(arrows)} arrows")
for node in results:
node["text"] = extract_text(image, node["bbox"], debug=debug_mode)
label = node.get("label", "box")
text = node["text"]
debug_log.append(f"π {node['id']} | Label: {label} | Text: {text}")
progress.progress(50, text="Mapping arrows to nodes...")
edges = map_arrows(results, arrows)
progress.progress(75, text="Building graph structure...")
flowchart = build_flowchart_json(results, edges)
progress.progress(90, text="Generating explanation...")
summary = summarize_flowchart(flowchart)
# Show Debug Info first
if debug_mode:
st.markdown("### π§ͺ Debug Info")
st.code("\n".join(debug_log), language="markdown")
st.markdown("### πΌοΈ YOLO Detected Bounding Boxes")
st.image(vis_debug, caption="YOLO Detected Boxes", use_container_width=True)
# Show results: JSON (left), Summary (right)
col1, col2 = st.columns(2)
with col1:
st.subheader("π§ Flowchart JSON")
st.json(flowchart)
with col2:
st.subheader("π English Summary")
st.markdown(summary)
progress.progress(100, text="Done!")
else:
st.info("Upload a flowchart image to begin.") |