acecalisto3 commited on
Commit
01b321a
1 Parent(s): 12b3c93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -21
app.py CHANGED
@@ -1044,30 +1044,91 @@ def create_gradio_interface():
1044
 
1045
  return interface
1046
 
1047
- # Create Gradio interface
1048
- interface = create_gradio_interface()
1049
-
1050
- # Flask routes
1051
- @app.route("/")
1052
- def home():
1053
- return render_template("index.html")
1054
-
1055
- @app.route("/api/execute", methods=["POST"])
1056
- def api_execute():
1057
- data = request.json
1058
- code = data.get("code", "")
1059
- autonomy_level = data.get("autonomy_level", 5)
1060
-
1061
- executor.set_autonomy_level(autonomy_level)
1062
- result = executor.execute_code(code)
1063
 
1064
- return jsonify(result)
 
 
 
 
 
 
 
 
 
1065
 
1066
- def run_flask():
1067
- app.run(host="0.0.0.0", port=5000)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1068
 
1069
- def run_gradio():
1070
- interface.launch(server_name="0.0.0.0", server_port=7860)
1071
 
1072
  if __name__ == "__main__":
1073
  # Run Flask and Gradio in separate threads
 
1044
 
1045
  return interface
1046
 
1047
+ def create_gradio_interface():
1048
+ """Create Gradio interface for the code executor"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1049
 
1050
+ def process_code(code: str, autonomy_level: int) -> Dict:
1051
+ executor.set_autonomy_level(autonomy_level)
1052
+ result = executor.execute_code(code)
1053
+ return {
1054
+ "Success": result["success"],
1055
+ "Output": result["output"],
1056
+ "Error": result["error"] or "None",
1057
+ "Fixed Code": result["fixed_code"] or code,
1058
+ "Iterations": result["iterations"]
1059
+ }
1060
 
1061
+ with gr.Blocks() as interface:
1062
+ gr.Markdown("# 🤖 Autonomous Code Executor")
1063
+
1064
+ with gr.Tab("Code Execution"):
1065
+ # Corrected Code component initialization
1066
+ code_input = gr.Code(
1067
+ label="Code Input",
1068
+ language="python",
1069
+ lines=10,
1070
+ value="# Enter your Python code here..." # Using value instead of placeholder
1071
+ )
1072
+
1073
+ autonomy_slider = gr.Slider(
1074
+ minimum=0,
1075
+ maximum=10,
1076
+ step=1,
1077
+ value=5,
1078
+ label="Autonomy Level",
1079
+ info="0: No fixes, 5: Balanced, 10: Fully autonomous"
1080
+ )
1081
+
1082
+ execute_btn = gr.Button("Execute Code", variant="primary")
1083
+ output_json = gr.JSON(label="Execution Result")
1084
+
1085
+ # Add example inputs
1086
+ gr.Examples(
1087
+ examples=[
1088
+ ["def hello():\n print('Hello, World!')", 5],
1089
+ ["for i in range(5):\n print(i)", 5]
1090
+ ],
1091
+ inputs=[code_input, autonomy_slider],
1092
+ outputs=output_json,
1093
+ label="Example Code"
1094
+ )
1095
+
1096
+ execute_btn.click(
1097
+ fn=process_code,
1098
+ inputs=[code_input, autonomy_slider],
1099
+ outputs=output_json
1100
+ )
1101
+
1102
+ with gr.Tab("Settings"):
1103
+ gr.Markdown("""
1104
+ ### Configuration
1105
+ - Model: bigcode/starcoder
1106
+ - Embedding Model: sentence-transformers/all-mpnet-base-v2
1107
+ - Temperature: 0.1
1108
+ - Max Length: 2048
1109
+ """)
1110
+
1111
+ with gr.Tab("Help"):
1112
+ gr.Markdown("""
1113
+ ### How to Use
1114
+ 1. Enter your Python code in the Code Input area
1115
+ 2. Adjust the Autonomy Level:
1116
+ - 0: No automatic fixes
1117
+ - 5: Balanced approach
1118
+ - 10: Fully autonomous operation
1119
+ 3. Click "Execute Code" to run
1120
+
1121
+ ### Features
1122
+ - Automatic code analysis
1123
+ - Error detection and fixing
1124
+ - Code formatting
1125
+ - Syntax validation
1126
+ """)
1127
+
1128
+ return interface
1129
 
1130
+ # Create Gradio interface
1131
+ interface = create_gradio_interface()
1132
 
1133
  if __name__ == "__main__":
1134
  # Run Flask and Gradio in separate threads