Spaces:
Sleeping
Sleeping
xyizko-Fix
Browse filesxyizko - Syntax and AgentCalls Fixes
app.py
CHANGED
|
@@ -114,7 +114,7 @@ def app_intro():
|
|
| 114 |
|
| 115 |
part3 = """
|
| 116 |
## Development Progress
|
| 117 |
-
> Changelog - Fri Jun 6
|
| 118 |
1. β
Implement robust AI analysis system
|
| 119 |
2. β
SmolAgents integration with proper error handling
|
| 120 |
3. β
Direct HF API fallback for maximum compatibility
|
|
@@ -123,6 +123,7 @@ def app_intro():
|
|
| 123 |
6. β
**NEW: Model Context Protocol (MCP) Integration**
|
| 124 |
7. β
**NEW: Single powerful MCP tool for AI assistants**
|
| 125 |
8. β
**NEW: Lightweight deployment (no transformers/torch dependencies)**
|
|
|
|
| 126 |
|
| 127 |
### About Author
|
| 128 |
1. X - https://x.com/xyizko
|
|
@@ -387,12 +388,14 @@ def enhanced_fallback_analysis(content, analysis_type):
|
|
| 387 |
- Add function visibility specifiers
|
| 388 |
- Consider gas optimization patterns"""
|
| 389 |
|
| 390 |
-
# ---
|
| 391 |
|
| 392 |
|
| 393 |
-
def
|
| 394 |
"""
|
| 395 |
-
|
|
|
|
|
|
|
| 396 |
|
| 397 |
Args:
|
| 398 |
contract_code: Solidity smart contract source code
|
|
@@ -546,7 +549,7 @@ def upload_tab():
|
|
| 546 |
- **facebook/blenderbot-400M-distill** (Lightweight, fast)
|
| 547 |
"""
|
| 548 |
|
| 549 |
-
def
|
| 550 |
if file is None:
|
| 551 |
return "β No file uploaded.", "", gr.update(visible=False)
|
| 552 |
|
|
@@ -572,8 +575,8 @@ def upload_tab():
|
|
| 572 |
|
| 573 |
progress(0.3, desc="π€ Running comprehensive analysis...")
|
| 574 |
|
| 575 |
-
# Use the
|
| 576 |
-
analysis_result =
|
| 577 |
content, hf_token, hf_model)
|
| 578 |
|
| 579 |
progress(0.9, desc="πΎ Creating downloadable report...")
|
|
@@ -667,7 +670,7 @@ def upload_tab():
|
|
| 667 |
)
|
| 668 |
|
| 669 |
analyze_btn.click(
|
| 670 |
-
fn=
|
| 671 |
inputs=[file_input, hf_token_input, hf_model_input],
|
| 672 |
outputs=[status_output, analysis_output, download_file]
|
| 673 |
)
|
|
@@ -734,8 +737,7 @@ def mcp_integration_tab():
|
|
| 734 |
return "β Please provide contract code to test the MCP tool"
|
| 735 |
|
| 736 |
try:
|
| 737 |
-
result =
|
| 738 |
-
contract_code, hf_token, hf_model)
|
| 739 |
return result
|
| 740 |
except Exception as e:
|
| 741 |
return f"β MCP Tool Error: {str(e)}"
|
|
@@ -827,45 +829,13 @@ contract TestContract {
|
|
| 827 |
outputs=[claude_config]
|
| 828 |
)
|
| 829 |
|
| 830 |
-
# --- Simple MCP Metadata ---
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
def add_mcp_metadata():
|
| 834 |
-
"""Simple MCP metadata for the single tool"""
|
| 835 |
-
return {
|
| 836 |
-
"mcp_tools": [
|
| 837 |
-
{
|
| 838 |
-
"name": "analyze_smart_contract",
|
| 839 |
-
"description": "Comprehensive smart contract security analysis with vulnerability detection, risk assessment, and code quality evaluation",
|
| 840 |
-
"parameters": {
|
| 841 |
-
"contract_code": {
|
| 842 |
-
"type": "string",
|
| 843 |
-
"required": True,
|
| 844 |
-
"description": "Solidity smart contract source code to analyze"
|
| 845 |
-
},
|
| 846 |
-
"hf_token": {
|
| 847 |
-
"type": "string",
|
| 848 |
-
"default": "",
|
| 849 |
-
"description": "Optional HuggingFace API token for AI-powered analysis"
|
| 850 |
-
},
|
| 851 |
-
"hf_model": {
|
| 852 |
-
"type": "string",
|
| 853 |
-
"default": "microsoft/DialoGPT-medium",
|
| 854 |
-
"description": "HuggingFace model name for AI analysis"
|
| 855 |
-
}
|
| 856 |
-
}
|
| 857 |
-
}
|
| 858 |
-
]
|
| 859 |
-
}
|
| 860 |
-
|
| 861 |
# /////////////////////////////////////////////////////////////////////////////////
|
| 862 |
# --- Main Demo UI Function ---
|
| 863 |
|
| 864 |
|
| 865 |
with gr.Blocks(
|
| 866 |
theme=gr.themes.Ocean(),
|
| 867 |
-
title="Xyizko - Smart Contract Analyzer"
|
| 868 |
-
**add_mcp_metadata()
|
| 869 |
) as demo:
|
| 870 |
|
| 871 |
with gr.Tab("π Introduction"):
|
|
@@ -879,12 +849,13 @@ with gr.Blocks(
|
|
| 879 |
|
| 880 |
if __name__ == "__main__":
|
| 881 |
print("π Starting Xyizko Smart Contract Analyzer...")
|
| 882 |
-
print("π MCP Integration: ENABLED (
|
| 883 |
print("π€ AI Analysis: SmolAgents + HF API with Fallback")
|
| 884 |
print("β‘ Lightweight: No transformers/torch dependencies")
|
| 885 |
print("π‘ Deploy to HuggingFace Spaces for public MCP access!")
|
| 886 |
|
| 887 |
demo.launch(
|
|
|
|
| 888 |
share=False,
|
| 889 |
server_name="0.0.0.0",
|
| 890 |
show_error=True
|
|
|
|
| 114 |
|
| 115 |
part3 = """
|
| 116 |
## Development Progress
|
| 117 |
+
> Changelog - Fri Jun 6 08:14:02 PM UTC 2025
|
| 118 |
1. β
Implement robust AI analysis system
|
| 119 |
2. β
SmolAgents integration with proper error handling
|
| 120 |
3. β
Direct HF API fallback for maximum compatibility
|
|
|
|
| 123 |
6. β
**NEW: Model Context Protocol (MCP) Integration**
|
| 124 |
7. β
**NEW: Single powerful MCP tool for AI assistants**
|
| 125 |
8. β
**NEW: Lightweight deployment (no transformers/torch dependencies)**
|
| 126 |
+
9. β
**NEW: Proper Gradio MCP server setup with mcp_server=True**
|
| 127 |
|
| 128 |
### About Author
|
| 129 |
1. X - https://x.com/xyizko
|
|
|
|
| 388 |
- Add function visibility specifiers
|
| 389 |
- Consider gas optimization patterns"""
|
| 390 |
|
| 391 |
+
# --- MCP Tool Function ---
|
| 392 |
|
| 393 |
|
| 394 |
+
def analyze_smart_contract(contract_code: str, hf_token: str = "", hf_model: str = "microsoft/DialoGPT-medium"):
|
| 395 |
"""
|
| 396 |
+
MCP Tool: Comprehensive smart contract security analysis
|
| 397 |
+
|
| 398 |
+
This function will be automatically exposed as an MCP tool when mcp_server=True
|
| 399 |
|
| 400 |
Args:
|
| 401 |
contract_code: Solidity smart contract source code
|
|
|
|
| 549 |
- **facebook/blenderbot-400M-distill** (Lightweight, fast)
|
| 550 |
"""
|
| 551 |
|
| 552 |
+
def analyze_contract_ui(file, hf_token, hf_model, progress=gr.Progress()):
|
| 553 |
if file is None:
|
| 554 |
return "β No file uploaded.", "", gr.update(visible=False)
|
| 555 |
|
|
|
|
| 575 |
|
| 576 |
progress(0.3, desc="π€ Running comprehensive analysis...")
|
| 577 |
|
| 578 |
+
# Use the MCP function for consistency
|
| 579 |
+
analysis_result = analyze_smart_contract(
|
| 580 |
content, hf_token, hf_model)
|
| 581 |
|
| 582 |
progress(0.9, desc="πΎ Creating downloadable report...")
|
|
|
|
| 670 |
)
|
| 671 |
|
| 672 |
analyze_btn.click(
|
| 673 |
+
fn=analyze_contract_ui,
|
| 674 |
inputs=[file_input, hf_token_input, hf_model_input],
|
| 675 |
outputs=[status_output, analysis_output, download_file]
|
| 676 |
)
|
|
|
|
| 737 |
return "β Please provide contract code to test the MCP tool"
|
| 738 |
|
| 739 |
try:
|
| 740 |
+
result = analyze_smart_contract(contract_code, hf_token, hf_model)
|
|
|
|
| 741 |
return result
|
| 742 |
except Exception as e:
|
| 743 |
return f"β MCP Tool Error: {str(e)}"
|
|
|
|
| 829 |
outputs=[claude_config]
|
| 830 |
)
|
| 831 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 832 |
# /////////////////////////////////////////////////////////////////////////////////
|
| 833 |
# --- Main Demo UI Function ---
|
| 834 |
|
| 835 |
|
| 836 |
with gr.Blocks(
|
| 837 |
theme=gr.themes.Ocean(),
|
| 838 |
+
title="Xyizko - Smart Contract Analyzer"
|
|
|
|
| 839 |
) as demo:
|
| 840 |
|
| 841 |
with gr.Tab("π Introduction"):
|
|
|
|
| 849 |
|
| 850 |
if __name__ == "__main__":
|
| 851 |
print("π Starting Xyizko Smart Contract Analyzer...")
|
| 852 |
+
print("π MCP Integration: ENABLED (mcp_server=True)")
|
| 853 |
print("π€ AI Analysis: SmolAgents + HF API with Fallback")
|
| 854 |
print("β‘ Lightweight: No transformers/torch dependencies")
|
| 855 |
print("π‘ Deploy to HuggingFace Spaces for public MCP access!")
|
| 856 |
|
| 857 |
demo.launch(
|
| 858 |
+
mcp_server=True,
|
| 859 |
share=False,
|
| 860 |
server_name="0.0.0.0",
|
| 861 |
show_error=True
|