removed deprecated code
Browse files
app.py
CHANGED
|
@@ -729,205 +729,6 @@ def generate_all_diagrams(
|
|
| 729 |
return uml_diagram_path, call_graph_path, analysis_text
|
| 730 |
|
| 731 |
|
| 732 |
-
# def generate_class_diagram(python_code: str) -> str:
|
| 733 |
-
# """Create a UML class diagram from Python code and return the PNG path.
|
| 734 |
-
|
| 735 |
-
# Args:
|
| 736 |
-
# python_code (str): Python source to analyse.
|
| 737 |
-
|
| 738 |
-
# Returns:
|
| 739 |
-
# str: Local path to a PNG image with the UML diagram.
|
| 740 |
-
# """
|
| 741 |
-
# result = generate_diagram(python_code)
|
| 742 |
-
# return result if result is not None else ""
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
# def generate_call_graph_diagram(python_code: str) -> str:
|
| 746 |
-
# """Create a function-call graph diagram (PNG).
|
| 747 |
-
|
| 748 |
-
# Args:
|
| 749 |
-
# python_code (str): Python source to analyse.
|
| 750 |
-
|
| 751 |
-
# Returns:
|
| 752 |
-
# str: Local path to the generated call-graph PNG.
|
| 753 |
-
# """
|
| 754 |
-
# _, png_path, _ = generate_call_graph_with_pyan3(python_code)
|
| 755 |
-
# return png_path or ""
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
# # -----------------------------------------------------------------------------
|
| 761 |
-
# # ❶ Four MCP‑exposed Interfaces ------------------------------------------------
|
| 762 |
-
# # -----------------------------------------------------------------------------
|
| 763 |
-
# iface_class = gr.Interface(
|
| 764 |
-
# fn=generate_class_diagram,
|
| 765 |
-
# inputs=gr.Textbox(lines=20, label="Python code"),
|
| 766 |
-
# outputs=gr.Image(label="UML diagram"),
|
| 767 |
-
# api_name="generate_class_diagram",
|
| 768 |
-
# description="Create a UML class diagram (PNG) from Python code.",
|
| 769 |
-
# )
|
| 770 |
-
|
| 771 |
-
# iface_call = gr.Interface(
|
| 772 |
-
# fn=generate_call_graph_diagram,
|
| 773 |
-
# inputs=gr.Textbox(lines=20, label="Python code"),
|
| 774 |
-
# outputs=gr.Image(label="Call‑graph"),
|
| 775 |
-
# api_name="generate_call_graph_diagram",
|
| 776 |
-
# description="Generate a function‑call graph (PNG) from Python code.",
|
| 777 |
-
# )
|
| 778 |
-
|
| 779 |
-
# iface_analysis = gr.Interface(
|
| 780 |
-
# fn=analyze_code_structure,
|
| 781 |
-
# inputs=gr.Textbox(lines=20, label="Python code"),
|
| 782 |
-
# outputs=gr.Textbox(lines=20, label="Analysis"),
|
| 783 |
-
# api_name="analyze_code_structure",
|
| 784 |
-
# description="Return a Markdown report with complexity metrics.",
|
| 785 |
-
# )
|
| 786 |
-
|
| 787 |
-
# iface_all = gr.Interface(
|
| 788 |
-
# fn=generate_all_diagrams,
|
| 789 |
-
# inputs=[
|
| 790 |
-
# gr.Textbox(lines=20, label="Python code"),
|
| 791 |
-
# gr.Textbox(value="diagram", label="Base filename"),
|
| 792 |
-
# ],
|
| 793 |
-
# outputs=[
|
| 794 |
-
# gr.Image(label="UML diagram"),
|
| 795 |
-
# gr.Image(label="Call‑graph"),
|
| 796 |
-
# gr.Textbox(lines=20, label="Analysis"),
|
| 797 |
-
# ],
|
| 798 |
-
# api_name="generate_all",
|
| 799 |
-
# description="Run class diagram, call graph and analysis in one call.",
|
| 800 |
-
# )
|
| 801 |
-
|
| 802 |
-
# # -----------------------------------------------------------------------------
|
| 803 |
-
# # ❷ Web UI (Blocks) -----------------------------------------------------------
|
| 804 |
-
# # -----------------------------------------------------------------------------
|
| 805 |
-
# with gr.Blocks(
|
| 806 |
-
# title="Python Diagram Generator MCP Demo",
|
| 807 |
-
# theme=gr.themes.Soft(),
|
| 808 |
-
# css="""
|
| 809 |
-
# .gradio-container { max-width: 1400px !important; }
|
| 810 |
-
# .code-input { font-family: 'Inter', monospace !important; }
|
| 811 |
-
# """,
|
| 812 |
-
# ) as demo:
|
| 813 |
-
|
| 814 |
-
# # -- Header ----------------------------------------------------------------
|
| 815 |
-
# gr.Markdown(
|
| 816 |
-
# """
|
| 817 |
-
# # 🐍 Python UML Diagram Generator & MCP Server
|
| 818 |
-
|
| 819 |
-
# **Dual Functionality**
|
| 820 |
-
# 1. 🖥️ *Web Interface* – generate UML & call‑graph diagrams + analysis
|
| 821 |
-
# 2. 🤖 *MCP Server* – four tools ready for assistants such as Claude Desktop or Cursor
|
| 822 |
-
# """
|
| 823 |
-
# )
|
| 824 |
-
|
| 825 |
-
# # -- Main TAB --------------------------------------------------------------
|
| 826 |
-
# with gr.Tab("🎨 Diagram Generator"):
|
| 827 |
-
# with gr.Row():
|
| 828 |
-
# # ---------- Left column – inputs -----------------------------------
|
| 829 |
-
# with gr.Column(scale=1):
|
| 830 |
-
# gr.Markdown("### Input")
|
| 831 |
-
|
| 832 |
-
# example_files = list_example_files()
|
| 833 |
-
# example_dropdown = gr.Dropdown(
|
| 834 |
-
# label="Choose Example",
|
| 835 |
-
# choices=example_files,
|
| 836 |
-
# value=example_files[0] if example_files else None,
|
| 837 |
-
# )
|
| 838 |
-
|
| 839 |
-
# code_input = gr.Textbox(
|
| 840 |
-
# label="Python Code",
|
| 841 |
-
# placeholder="Paste your Python code here…",
|
| 842 |
-
# lines=20,
|
| 843 |
-
# max_lines=35,
|
| 844 |
-
# value=get_sample_code(example_files[0]) if example_files else "",
|
| 845 |
-
# elem_classes=["code-input"],
|
| 846 |
-
# )
|
| 847 |
-
|
| 848 |
-
# filename_input = gr.Textbox(
|
| 849 |
-
# label="Diagram Name",
|
| 850 |
-
# value="my_diagram",
|
| 851 |
-
# placeholder="Enter a name for your diagram",
|
| 852 |
-
# )
|
| 853 |
-
|
| 854 |
-
# generate_diagrams_btn = gr.Button(
|
| 855 |
-
# "🔄 Generate Diagrams", variant="primary", size="lg"
|
| 856 |
-
# )
|
| 857 |
-
|
| 858 |
-
# # ---------- Right column – outputs ---------------------------------
|
| 859 |
-
# with gr.Column(scale=1):
|
| 860 |
-
# gr.Markdown("### Generated UML Class Diagram")
|
| 861 |
-
# uml_diagram_output = gr.Image(
|
| 862 |
-
# label="UML Class Diagram", show_download_button=True, height=300
|
| 863 |
-
# )
|
| 864 |
-
|
| 865 |
-
# gr.Markdown("### Generated Call Graph Diagram")
|
| 866 |
-
# call_graph_output = gr.Image(
|
| 867 |
-
# label="Function Call Graph", show_download_button=True, height=300
|
| 868 |
-
# )
|
| 869 |
-
|
| 870 |
-
# # ---------- Analysis row ----------------------------------------------
|
| 871 |
-
# gr.Markdown("### Code Analysis")
|
| 872 |
-
# analysis_output = gr.Textbox(
|
| 873 |
-
# label="Comprehensive Code Analysis",
|
| 874 |
-
# lines=15,
|
| 875 |
-
# max_lines=25,
|
| 876 |
-
# interactive=False,
|
| 877 |
-
# show_copy_button=True,
|
| 878 |
-
# )
|
| 879 |
-
|
| 880 |
-
# # -- About TAB -------------------------------------------------------------
|
| 881 |
-
# # with gr.Tab("ℹ️ About & Help"):
|
| 882 |
-
# # gr.Markdown(open("ABOUT.md", "r", encoding="utf-8").read()) # keep long text external
|
| 883 |
-
|
| 884 |
-
# # -- Hidden TabbedInterface to register MCP tools -------------------------
|
| 885 |
-
# # (render=False avoids GUI duplication)
|
| 886 |
-
# # gr.TabbedInterface(
|
| 887 |
-
# # [iface_class, iface_call, iface_analysis, iface_all],
|
| 888 |
-
# # ["Class diagram", "Call graph", "Analysis", "All‑in‑one"],
|
| 889 |
-
# # # render=False,
|
| 890 |
-
# # )
|
| 891 |
-
|
| 892 |
-
# # -------------------------------------------------------------------------
|
| 893 |
-
# # Event handlers -----------------------------------------------------------
|
| 894 |
-
# # -------------------------------------------------------------------------
|
| 895 |
-
|
| 896 |
-
# def _load_example(example_filename: str):
|
| 897 |
-
# """Load bundled example code into the textbox."""
|
| 898 |
-
# return get_sample_code(example_filename)
|
| 899 |
-
|
| 900 |
-
# example_dropdown.change(_load_example, example_dropdown, code_input)
|
| 901 |
-
|
| 902 |
-
# generate_diagrams_btn.click(
|
| 903 |
-
# fn=generate_all_diagrams,
|
| 904 |
-
# inputs=[code_input, filename_input],
|
| 905 |
-
# outputs=[uml_diagram_output, call_graph_output, analysis_output],
|
| 906 |
-
# show_progress=True,
|
| 907 |
-
# )
|
| 908 |
-
|
| 909 |
-
# # code_input.change(
|
| 910 |
-
# # fn=analyze_code_structure,
|
| 911 |
-
# # inputs=code_input,
|
| 912 |
-
# # outputs=analysis_output,
|
| 913 |
-
# # show_progress=False,
|
| 914 |
-
# # )
|
| 915 |
-
|
| 916 |
-
# # -----------------------------------------------------------------------------
|
| 917 |
-
# # ❸ Launch -------------------------------------------------------------------
|
| 918 |
-
# # -----------------------------------------------------------------------------
|
| 919 |
-
# if __name__ == "__main__":
|
| 920 |
-
# setup_testing_space() # create a persistent working dir if needed
|
| 921 |
-
|
| 922 |
-
# demo.launch(
|
| 923 |
-
# mcp_server=True, # Enable MCP endpoints (/gradio_api/mcp/*)
|
| 924 |
-
# show_api=False, # Expose ONLY the 4 Interfaces as tools
|
| 925 |
-
# show_error=True, # Display exceptions in the UI
|
| 926 |
-
# debug=True, # Verbose server logs
|
| 927 |
-
# )
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
# =============================================================================
|
| 932 |
# ❶ Wrapper functions for diagram and analysis generation
|
| 933 |
# These will be connected to the UI buttons and the MCP interfaces.
|
|
|
|
| 729 |
return uml_diagram_path, call_graph_path, analysis_text
|
| 730 |
|
| 731 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 732 |
# =============================================================================
|
| 733 |
# ❶ Wrapper functions for diagram and analysis generation
|
| 734 |
# These will be connected to the UI buttons and the MCP interfaces.
|