S-Dreamer commited on
Commit
4b36103
·
verified ·
1 Parent(s): 4590a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -32
app.py CHANGED
@@ -1,38 +1,33 @@
1
  import gradio as gr
2
- import requests
3
-
4
- # --- Inference Logic ---
5
- def detect_language(code_snippet, token):
6
- headers = {"Authorization": f"Bearer {token}"} if token else {}
7
- response = requests.post(
8
- "https://api-inference.huggingface.co/models/huggingface/CodeBERTa-language-id",
9
- headers=headers,
10
- json={"inputs": code_snippet}
11
- )
12
- if response.status_code == 200:
13
- prediction = response.json()[0]['label']
14
- return f"Detected Language: {prediction}"
15
- else:
16
- return f"Error: {response.text}"
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
- code_input = gr.Code(label="Paste your code snippet here")
30
- token_input = gr.Textbox(label="Hugging Face Access Token (optional)", type="password", placeholder="hf_...")
31
- detect_btn = gr.Button("Detect Language")
32
- with gr.Column():
33
- output = gr.Textbox(label="Result", lines=3)
 
 
 
 
 
34
 
35
- detect_btn.click(fn=detect_language, inputs=[code_input, token_input], outputs=output)
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()