File size: 2,171 Bytes
6008791
 
 
 
 
 
 
 
 
 
5c61522
 
 
6008791
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff0543a
 
 
 
 
 
 
 
 
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
# ==============================
# app.py β€” Gradio UI Entry Point
# ==============================

from dotenv import load_dotenv
load_dotenv(dotenv_path=".env", override=True)

import os
import gradio as gr

USERNAME = os.environ.get("APP_USERNAME")
PASSWORD = os.environ.get("APP_PASSWORD")

# --- Sanity check (safe to remove later) ---
print("OPENAI_API_KEY exists:", bool(os.getenv("OPENAI_API_KEY")))

from inclusive_writer.run_pipeline import generate_inclusive_text

DESCRIPTION = """

### 🌍 Gender-Inclusive Writing Assistant



Developed using **CrewAI + RAG-based Inclusive Glossary**.

"""
def run_inclusive_writer(user_input: str):
    if not user_input or not user_input.strip():
        return "", "", "⚠️ Please enter some text."

    try:
        result = generate_inclusive_text(user_input.strip())
        return (
            result["analysis"],
            result["guidance"],
            result["inclusive_output"]
        )
    except Exception as e:
        return "", "", f"❌ Error: {str(e)}"

with gr.Blocks() as demo:
    gr.Markdown("# ✍️ Inclusive Writing Assistant")
    gr.Markdown(DESCRIPTION)

    input_text = gr.Textbox(
        label="Input Text",
        placeholder="Enter your text here...",
        lines=5
    )

    submit_btn = gr.Button("Generate Inclusive Version")

    with gr.Accordion("🧠 Analysis (Bias & Intent Detection)", open=False):
        analysis_box = gr.Textbox(lines=8, label="Analysis")

    with gr.Accordion("πŸ“Œ Guidance (Inclusion Strategy)", open=False):
        guidance_box = gr.Textbox(lines=8, label="Guidance")

    gr.Markdown("### βœ… Inclusive & Professional Output")
    output_box = gr.Textbox(lines=10, label="Inclusive Output")

    submit_btn.click(
        fn=run_inclusive_writer,
        inputs=input_text,
        outputs=[analysis_box, guidance_box, output_box]
    )

# app = demo.launch(auth=(USERNAME, PASSWORD))
if __name__ == "__main__":
    port = int(os.getenv("PORT", 7860))

    demo.launch(
        auth=(USERNAME, PASSWORD),
        server_name="0.0.0.0",
        server_port=port
    )