Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
from graph_pipeline import textdoctor_app, TextDoctorState
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="TextDoctor – Multi-Agent Text Polisher",
|
| 8 |
+
page_icon="🩺",
|
| 9 |
+
layout="wide"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
st.title("🩺 TextDoctor – Multi-Agent Text Improvement")
|
| 13 |
+
st.write(
|
| 14 |
+
"Give me your **informal / messy text**, and I’ll run it through "
|
| 15 |
+
"grammar, style, and clarity agents, then a reviewer agent will pick "
|
| 16 |
+
"the best professional version with explanations."
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# --- Input area ---
|
| 20 |
+
default_example = (
|
| 21 |
+
"bro i need 2 more days for this, hope thats okay, "
|
| 22 |
+
"i had some issues so couldnt finish on time"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
user_text = st.text_area(
|
| 26 |
+
"Enter your text here:",
|
| 27 |
+
value=default_example,
|
| 28 |
+
height=150
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
col1, col2 = st.columns([1, 3])
|
| 32 |
+
|
| 33 |
+
with col1:
|
| 34 |
+
run_button = st.button("Run TextDoctor 🚀")
|
| 35 |
+
|
| 36 |
+
if run_button and user_text.strip():
|
| 37 |
+
with st.spinner("Running multi-agent pipeline..."):
|
| 38 |
+
# Prepare initial state for LangGraph app
|
| 39 |
+
state: TextDoctorState = {"input_text": user_text}
|
| 40 |
+
final_state = textdoctor_app.invoke(state)
|
| 41 |
+
|
| 42 |
+
review = final_state["review_result"]
|
| 43 |
+
final_text = review["final_text"]
|
| 44 |
+
|
| 45 |
+
st.subheader("✅ Final Professional Version")
|
| 46 |
+
st.success(final_text)
|
| 47 |
+
|
| 48 |
+
with st.expander("🧠 Why this version? (Reviewer Agent Explanation)", expanded=False):
|
| 49 |
+
st.write(review["decision_explanation"])
|
| 50 |
+
|
| 51 |
+
# --- Show intermediate steps ---
|
| 52 |
+
st.subheader("🔍 Agent-wise Transformations")
|
| 53 |
+
|
| 54 |
+
tab1, tab2, tab3 = st.tabs(["Grammar Agent", "Style Agent", "Clarity Agent"])
|
| 55 |
+
|
| 56 |
+
with tab1:
|
| 57 |
+
g_res = final_state["grammar_result"]
|
| 58 |
+
st.markdown("**Output:**")
|
| 59 |
+
st.write(g_res["corrected"])
|
| 60 |
+
st.markdown("**Changes detected:**")
|
| 61 |
+
if g_res.get("changes"):
|
| 62 |
+
for c in g_res["changes"]:
|
| 63 |
+
st.write(f"- `{c.get('from')}` → `{c.get('to')}` ({c.get('type')})")
|
| 64 |
+
else:
|
| 65 |
+
st.write("No explicit changes detected or diff too small.")
|
| 66 |
+
|
| 67 |
+
with tab2:
|
| 68 |
+
s_res = final_state["style_result"]
|
| 69 |
+
st.markdown("**Output:**")
|
| 70 |
+
st.write(s_res["styled"])
|
| 71 |
+
st.markdown("**Changes detected:**")
|
| 72 |
+
if s_res.get("changes"):
|
| 73 |
+
for c in s_res["changes"]:
|
| 74 |
+
st.write(f"- `{c.get('from')}` → `{c.get('to')}` ({c.get('type')})")
|
| 75 |
+
else:
|
| 76 |
+
st.write("No explicit changes detected or diff too small.")
|
| 77 |
+
|
| 78 |
+
with tab3:
|
| 79 |
+
c_res = final_state["clarity_result"]
|
| 80 |
+
st.markdown("**Output:**")
|
| 81 |
+
st.write(c_res["clarified"])
|
| 82 |
+
st.markdown("**Changes detected:**")
|
| 83 |
+
if c_res.get("changes"):
|
| 84 |
+
for c in c_res["changes"]:
|
| 85 |
+
st.write(f"- `{c.get('from')}` → `{c.get('to')}` ({c.get('type')})")
|
| 86 |
+
else:
|
| 87 |
+
st.write("No explicit changes detected or diff too small.")
|
| 88 |
+
|
| 89 |
+
# --- Candidate scores table ---
|
| 90 |
+
st.subheader("📊 Candidate Comparison (Reviewer Agent)")
|
| 91 |
+
|
| 92 |
+
cand_rows = []
|
| 93 |
+
for c in review["candidates"]:
|
| 94 |
+
cand_rows.append({
|
| 95 |
+
"Candidate": c["name"],
|
| 96 |
+
"Score": c["score"],
|
| 97 |
+
"Text": c["text"],
|
| 98 |
+
"Notes": c["notes"]
|
| 99 |
+
})
|
| 100 |
+
|
| 101 |
+
st.table(cand_rows)
|
| 102 |
+
|
| 103 |
+
elif run_button and not user_text.strip():
|
| 104 |
+
st.warning("Please enter some text before running TextDoctor.")
|