xyizko commited on
Commit
e545018
Β·
verified Β·
1 Parent(s): ebe5caa

xyizko-Fix

Browse files

xyizko - Syntax and AgentCalls Fixes

Files changed (1) hide show
  1. app.py +15 -44
app.py CHANGED
@@ -114,7 +114,7 @@ def app_intro():
114
 
115
  part3 = """
116
  ## Development Progress
117
- > Changelog - Fri Jun 6 07:15:00 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 +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
- # --- Single Powerful MCP Tool ---
391
 
392
 
393
- def analyze_smart_contract_mcp(contract_code: str, hf_token: str = "", hf_model: str = "microsoft/DialoGPT-medium"):
394
  """
395
- Single comprehensive MCP tool for smart contract analysis
 
 
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 analyze_contract(file, hf_token, hf_model, progress=gr.Progress()):
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 same MCP function for consistency
576
- analysis_result = analyze_smart_contract_mcp(
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=analyze_contract,
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 = analyze_smart_contract_mcp(
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 (Single Powerful Tool)")
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