Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# --- Gradio Interface ---
|
| 19 |
-
with gr.Blocks(title="SecuPromptMCP - Language Detection") as demo:
|
| 20 |
-
with gr.Row():
|
| 21 |
-
gr.Markdown("# 🔐 SecuPromptMCP")
|
| 22 |
-
gr.Markdown(
|
| 23 |
-
"This tool uses the `huggingface/CodeBERTa-language-id` model to detect the programming language from code snippets. "
|
| 24 |
-
"Sign in with your Hugging Face account to use the Inference API. Perfect for pentesters, devs, and agents on the edge."
|
| 25 |
-
)
|
| 26 |
|
| 27 |
with gr.Row():
|
| 28 |
-
with gr.Column():
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
# --- Launch App ---
|
| 38 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import black
|
| 3 |
+
import isort
|
| 4 |
+
|
| 5 |
+
def format_code(code: str, apply_black=True, apply_isort=True) -> str:
|
| 6 |
+
try:
|
| 7 |
+
if apply_black:
|
| 8 |
+
code = black.format_str(code, mode=black.Mode())
|
| 9 |
+
if apply_isort:
|
| 10 |
+
code = isort.code(code)
|
| 11 |
+
return code
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"⚠️ Error during formatting: {str(e)}"
|
| 14 |
+
|
| 15 |
+
with gr.Blocks(title="🧰 Python Configurator") as demo:
|
| 16 |
+
gr.Markdown("# 🧰 Python Configurator\nFormat, lint, and inspect your Python configuration files easily.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
with gr.Row():
|
| 19 |
+
with gr.Column(scale=1):
|
| 20 |
+
input_code = gr.Code(label="Paste your Python config", language="python", lines=20)
|
| 21 |
+
|
| 22 |
+
with gr.Row():
|
| 23 |
+
use_black = gr.Checkbox(label="Apply Black Formatter", value=True)
|
| 24 |
+
use_isort = gr.Checkbox(label="Apply isort", value=True)
|
| 25 |
+
|
| 26 |
+
submit_btn = gr.Button("Format Code")
|
| 27 |
+
|
| 28 |
+
with gr.Column(scale=1):
|
| 29 |
+
output_code = gr.Code(label="Formatted Output", language="python", lines=20)
|
| 30 |
|
| 31 |
+
submit_btn.click(fn=format_code, inputs=[input_code, use_black, use_isort], outputs=output_code)
|
| 32 |
|
|
|
|
| 33 |
demo.launch()
|