Spaces:
Runtime error
Runtime error
Download app.py from Unit4IAI/GenderInclusive: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/spaces/Unit4IAI/GenderInclusive/resolve/main/app.py
- Command line
-
hf download hf://spaces/Unit4IAI/GenderInclusive/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Unit4IAI/GenderInclusive/resolve/main/app.py
2.17 kB
| # ============================== | |
| # 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 | |
| ) | |