Spaces:
Sleeping
Sleeping
Venkat V
commited on
Commit
Β·
c20d656
1
Parent(s):
c842ab7
FIXed imports
Browse files- api_backend.py +1 -1
- app.py +34 -22
api_backend.py
CHANGED
@@ -10,7 +10,7 @@ import base64
|
|
10 |
# π‘ Import modules
|
11 |
from yolo_module import run_yolo
|
12 |
from ocr_module import extract_text, count_elements, validate_structure
|
13 |
-
from
|
14 |
from summarizer_module import summarize_flowchart
|
15 |
|
16 |
app = FastAPI()
|
|
|
10 |
# π‘ Import modules
|
11 |
from yolo_module import run_yolo
|
12 |
from ocr_module import extract_text, count_elements, validate_structure
|
13 |
+
from graph_module import map_arrows, build_flowchart_json
|
14 |
from summarizer_module import summarize_flowchart
|
15 |
|
16 |
app = FastAPI()
|
app.py
CHANGED
@@ -1,23 +1,29 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import io
|
4 |
import base64
|
5 |
import os
|
6 |
|
7 |
-
|
8 |
-
from
|
9 |
-
from
|
10 |
-
from
|
|
|
11 |
|
12 |
st.set_page_config(page_title="Flowchart to English", layout="wide")
|
13 |
st.title("π Flowchart to Plain English")
|
14 |
|
|
|
15 |
debug_mode = st.toggle("π§ Show Debug Info", value=False)
|
16 |
|
|
|
17 |
uploaded_file = st.file_uploader("Upload a flowchart image", type=["png", "jpg", "jpeg"])
|
18 |
|
19 |
if uploaded_file:
|
20 |
-
image = Image.open(uploaded_file)
|
|
|
|
|
21 |
max_width = 600
|
22 |
ratio = max_width / float(image.size[0])
|
23 |
resized_image = image.resize((max_width, int(image.size[1] * ratio)))
|
@@ -26,19 +32,36 @@ if uploaded_file:
|
|
26 |
if st.button("π Analyze Flowchart"):
|
27 |
progress = st.progress(0, text="Detecting boxes and arrows...")
|
28 |
results, arrows, vis_debug = run_yolo(image)
|
29 |
-
progress.progress(
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
# Add text to results
|
32 |
for node in results:
|
33 |
node["text"] = extract_text(image, node["bbox"], debug=debug_mode)
|
|
|
|
|
|
|
34 |
|
35 |
-
progress.progress(
|
36 |
edges = map_arrows(results, arrows)
|
|
|
|
|
37 |
flowchart = build_flowchart_json(results, edges)
|
38 |
|
39 |
-
progress.progress(
|
40 |
summary = summarize_flowchart(flowchart)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
col1, col2 = st.columns(2)
|
43 |
with col1:
|
44 |
st.subheader("π§ Flowchart JSON")
|
@@ -47,18 +70,7 @@ if uploaded_file:
|
|
47 |
st.subheader("π English Summary")
|
48 |
st.markdown(summary)
|
49 |
|
50 |
-
if debug_mode:
|
51 |
-
st.subheader("πΌοΈ YOLO Visual Debug")
|
52 |
-
st.image(vis_debug, caption="Detected Boxes & Arrows", use_container_width=True)
|
53 |
-
|
54 |
progress.progress(100, text="Done!")
|
|
|
55 |
else:
|
56 |
-
st.info("Upload a flowchart image to begin.")
|
57 |
-
|
58 |
-
# For Render compatibility
|
59 |
-
if __name__ == "__main__":
|
60 |
-
import streamlit.web.cli as stcli
|
61 |
-
import sys
|
62 |
-
port = int(os.environ.get("PORT", 7860))
|
63 |
-
sys.argv = ["streamlit", "run", "app.py", "--server.port", str(port), "--server.address=0.0.0.0"]
|
64 |
-
sys.exit(stcli.main())
|
|
|
1 |
+
# app.py
|
2 |
import streamlit as st
|
3 |
from PIL import Image
|
4 |
import io
|
5 |
import base64
|
6 |
import os
|
7 |
|
8 |
+
# Local modules
|
9 |
+
from yolo_module import run_yolo
|
10 |
+
from ocr_module import extract_text
|
11 |
+
from graph_module import map_arrows, build_flowchart_json
|
12 |
+
from summarizer_module import summarize_flowchart
|
13 |
|
14 |
st.set_page_config(page_title="Flowchart to English", layout="wide")
|
15 |
st.title("π Flowchart to Plain English")
|
16 |
|
17 |
+
# Enable debug mode
|
18 |
debug_mode = st.toggle("π§ Show Debug Info", value=False)
|
19 |
|
20 |
+
# Upload image
|
21 |
uploaded_file = st.file_uploader("Upload a flowchart image", type=["png", "jpg", "jpeg"])
|
22 |
|
23 |
if uploaded_file:
|
24 |
+
image = Image.open(uploaded_file).convert("RGB")
|
25 |
+
|
26 |
+
# Show resized preview
|
27 |
max_width = 600
|
28 |
ratio = max_width / float(image.size[0])
|
29 |
resized_image = image.resize((max_width, int(image.size[1] * ratio)))
|
|
|
32 |
if st.button("π Analyze Flowchart"):
|
33 |
progress = st.progress(0, text="Detecting boxes and arrows...")
|
34 |
results, arrows, vis_debug = run_yolo(image)
|
35 |
+
progress.progress(25, text="Running OCR...")
|
36 |
+
|
37 |
+
debug_log = []
|
38 |
+
debug_log.append(f"π¦ Detected {len(results)} boxes")
|
39 |
+
debug_log.append(f"β‘οΈ Detected {len(arrows)} arrows")
|
40 |
|
|
|
41 |
for node in results:
|
42 |
node["text"] = extract_text(image, node["bbox"], debug=debug_mode)
|
43 |
+
label = node.get("label", "box")
|
44 |
+
text = node["text"]
|
45 |
+
debug_log.append(f"π {node['id']} | Label: {label} | Text: {text}")
|
46 |
|
47 |
+
progress.progress(50, text="Mapping arrows to nodes...")
|
48 |
edges = map_arrows(results, arrows)
|
49 |
+
|
50 |
+
progress.progress(75, text="Building graph structure...")
|
51 |
flowchart = build_flowchart_json(results, edges)
|
52 |
|
53 |
+
progress.progress(90, text="Generating explanation...")
|
54 |
summary = summarize_flowchart(flowchart)
|
55 |
|
56 |
+
# Show Debug Info first
|
57 |
+
if debug_mode:
|
58 |
+
st.markdown("### π§ͺ Debug Info")
|
59 |
+
st.code("\n".join(debug_log), language="markdown")
|
60 |
+
|
61 |
+
st.markdown("### πΌοΈ YOLO Detected Bounding Boxes")
|
62 |
+
st.image(vis_debug, caption="YOLO Detected Boxes", use_container_width=True)
|
63 |
+
|
64 |
+
# Show results: JSON (left), Summary (right)
|
65 |
col1, col2 = st.columns(2)
|
66 |
with col1:
|
67 |
st.subheader("π§ Flowchart JSON")
|
|
|
70 |
st.subheader("π English Summary")
|
71 |
st.markdown(summary)
|
72 |
|
|
|
|
|
|
|
|
|
73 |
progress.progress(100, text="Done!")
|
74 |
+
|
75 |
else:
|
76 |
+
st.info("Upload a flowchart image to begin.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|