Fix runtime errors: transformers version pin, Gradio 6.0 compatibility, tokenizer deps, API endpoints
Browse files
app.py
CHANGED
|
@@ -401,8 +401,6 @@ def verify_password(password, stored):
|
|
| 401 |
# ============================================================
|
| 402 |
with gr.Blocks(
|
| 403 |
title="Code Security Risk Analyzer",
|
| 404 |
-
theme=gr.themes.Soft(),
|
| 405 |
-
css=".gradio-container { max-width: 1200px; margin: auto; }"
|
| 406 |
) as demo:
|
| 407 |
gr.Markdown("""
|
| 408 |
# π AI-Powered Code Security Risk Analyzer
|
|
@@ -428,9 +426,14 @@ with gr.Blocks(
|
|
| 428 |
def show_json(code):
|
| 429 |
return gr.update(visible=True, value=get_json_report(code))
|
| 430 |
|
| 431 |
-
analyze_btn.click(fn=analyze_code, inputs=[code_input], outputs=[report_output])
|
| 432 |
json_btn.click(fn=show_json, inputs=[code_input], outputs=[json_output])
|
| 433 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
with gr.Accordion("π REST API Documentation", open=False):
|
| 435 |
gr.Markdown("""
|
| 436 |
### Python Client
|
|
@@ -449,13 +452,13 @@ json_report = client.predict(code="your code here", api_name="/get_json_report")
|
|
| 449 |
### cURL
|
| 450 |
```bash
|
| 451 |
# Markdown report
|
| 452 |
-
curl -X POST https://ayshajavd-code-security-analyzer.hf.space/call/analyze \
|
| 453 |
-
-H "Content-Type: application/json" \
|
| 454 |
-d '{"data": ["your code here"]}'
|
| 455 |
|
| 456 |
# JSON report
|
| 457 |
-
curl -X POST https://ayshajavd-code-security-analyzer.hf.space/call/get_json_report \
|
| 458 |
-
-H "Content-Type: application/json" \
|
| 459 |
-d '{"data": ["your code here"]}'
|
| 460 |
```
|
| 461 |
|
|
@@ -484,14 +487,6 @@ curl -X POST https://ayshajavd-code-security-analyzer.hf.space/call/get_json_rep
|
|
| 484 |
```
|
| 485 |
""")
|
| 486 |
|
| 487 |
-
# Explicit API endpoint for JSON reports
|
| 488 |
-
json_api = gr.Interface(
|
| 489 |
-
fn=get_json_report,
|
| 490 |
-
inputs=gr.Textbox(label="code"),
|
| 491 |
-
outputs=gr.JSON(label="report"),
|
| 492 |
-
api_name="get_json_report",
|
| 493 |
-
)
|
| 494 |
-
|
| 495 |
gr.Markdown("""
|
| 496 |
---
|
| 497 |
### 30 CWE Vulnerability Classes β OWASP Top 10
|
|
@@ -508,4 +503,7 @@ curl -X POST https://ayshajavd-code-security-analyzer.hf.space/call/get_json_rep
|
|
| 508 |
""")
|
| 509 |
|
| 510 |
if __name__ == "__main__":
|
| 511 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
# ============================================================
|
| 402 |
with gr.Blocks(
|
| 403 |
title="Code Security Risk Analyzer",
|
|
|
|
|
|
|
| 404 |
) as demo:
|
| 405 |
gr.Markdown("""
|
| 406 |
# π AI-Powered Code Security Risk Analyzer
|
|
|
|
| 426 |
def show_json(code):
|
| 427 |
return gr.update(visible=True, value=get_json_report(code))
|
| 428 |
|
| 429 |
+
analyze_btn.click(fn=analyze_code, inputs=[code_input], outputs=[report_output], api_name="analyze")
|
| 430 |
json_btn.click(fn=show_json, inputs=[code_input], outputs=[json_output])
|
| 431 |
|
| 432 |
+
# Hidden API-only endpoint for raw JSON reports
|
| 433 |
+
with gr.Row(visible=False):
|
| 434 |
+
api_json_btn = gr.Button("get_json", visible=False)
|
| 435 |
+
api_json_btn.click(fn=get_json_report, inputs=[code_input], outputs=[json_output], api_name="get_json_report")
|
| 436 |
+
|
| 437 |
with gr.Accordion("π REST API Documentation", open=False):
|
| 438 |
gr.Markdown("""
|
| 439 |
### Python Client
|
|
|
|
| 452 |
### cURL
|
| 453 |
```bash
|
| 454 |
# Markdown report
|
| 455 |
+
curl -X POST https://ayshajavd-code-security-analyzer.hf.space/call/analyze \
|
| 456 |
+
-H "Content-Type: application/json" \
|
| 457 |
-d '{"data": ["your code here"]}'
|
| 458 |
|
| 459 |
# JSON report
|
| 460 |
+
curl -X POST https://ayshajavd-code-security-analyzer.hf.space/call/get_json_report \
|
| 461 |
+
-H "Content-Type: application/json" \
|
| 462 |
-d '{"data": ["your code here"]}'
|
| 463 |
```
|
| 464 |
|
|
|
|
| 487 |
```
|
| 488 |
""")
|
| 489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
gr.Markdown("""
|
| 491 |
---
|
| 492 |
### 30 CWE Vulnerability Classes β OWASP Top 10
|
|
|
|
| 503 |
""")
|
| 504 |
|
| 505 |
if __name__ == "__main__":
|
| 506 |
+
demo.launch(
|
| 507 |
+
theme=gr.themes.Soft(),
|
| 508 |
+
css=".gradio-container { max-width: 1200px; margin: auto; }"
|
| 509 |
+
)
|