Spaces:
Configuration error
Configuration error
| import gradio as gr | |
| import black | |
| import isort | |
| def format_code(code: str, apply_black=True, apply_isort=True) -> str: | |
| try: | |
| if apply_black: | |
| code = black.format_str(code, mode=black.Mode()) | |
| if apply_isort: | |
| code = isort.code(code) | |
| return code | |
| except Exception as e: | |
| return f"⚠️ Error during formatting: {str(e)}" | |
| with gr.Blocks(title="🧰 Python Configurator") as demo: | |
| gr.Markdown("# 🧰 Python Configurator\nFormat, lint, and inspect your Python configuration files easily.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| input_code = gr.Code(label="Paste your Python config", language="python", lines=20) | |
| with gr.Row(): | |
| use_black = gr.Checkbox(label="Apply Black Formatter", value=True) | |
| use_isort = gr.Checkbox(label="Apply isort", value=True) | |
| submit_btn = gr.Button("Format Code") | |
| with gr.Column(scale=1): | |
| output_code = gr.Code(label="Formatted Output", language="python", lines=20) | |
| submit_btn.click(fn=format_code, inputs=[input_code, use_black, use_isort], outputs=output_code) | |
| demo.launch() |