Spaces:
Configuration error
Configuration error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|