acecalisto3 commited on
Commit
12b3c93
1 Parent(s): 38e3e8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -30
app.py CHANGED
@@ -972,40 +972,117 @@ class GradioInterface:
972
  generate_preview,
973
  outputs=[preview_status]
974
  )
975
- def _create_ai_tab(self):
976
- """Create AI assistant tab with streamlined yes/no interaction"""
977
- with gr.Row():
978
- with gr.Column(scale=2):
979
- gr.Markdown("""### 🤖 AI Assistant - Quick Build
980
- Start by selecting your main task, then answer with Yes/No to refine the solution.
981
-
982
- Available Commands:
983
- 1. create - New app
984
- 2. component - Add/modify components
985
- 3. layout - Change layout
986
- 4. style - Customize appearance
987
- 5. data - Data processing
988
- 6. api - API integration
989
- 7. auth - Authentication
990
- 8. file - File operations
991
- 9. viz - Visualization
992
- 10. db - Database
993
- """)
 
 
 
 
 
994
 
995
- chat_history = gr.Chatbot(label="Interaction History")
996
- user_input = gr.Radio(
997
- choices=["Yes", "No"],
998
- label="Your Response",
999
- visible=False
 
 
1000
  )
1001
- command_input = gr.Dropdown(
1002
- choices=["create", "component", "layout", "style", "data", "api", "auth", "file", "viz", "db"],
1003
- label="Select Command to Start",
 
 
 
 
 
 
1004
  )
1005
- with gr.Row():
1006
- send_btn = gr.Button("Send", variant="primary")
1007
- restart_btn = gr.Button("Restart", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1009
  class ChatState:
1010
  def __init__(self):
1011
  self.current_step = 0
 
972
  generate_preview,
973
  outputs=[preview_status]
974
  )
975
+ def create_gradio_interface():
976
+ """Create Gradio interface for the code executor"""
977
+
978
+ def process_code(code: str, autonomy_level: int) -> Dict:
979
+ executor.set_autonomy_level(autonomy_level)
980
+ result = executor.execute_code(code)
981
+ return {
982
+ "Success": result["success"],
983
+ "Output": result["output"],
984
+ "Error": result["error"] or "None",
985
+ "Fixed Code": result["fixed_code"] or code,
986
+ "Iterations": result["iterations"]
987
+ }
988
+
989
+ with gr.Blocks() as interface:
990
+ gr.Markdown("# 🤖 Autonomous Code Executor")
991
+
992
+ with gr.Tab("Code Execution"):
993
+ code_input = gr.Code(
994
+ label="Code Input",
995
+ language="python",
996
+ lines=10,
997
+ placeholder="Enter your Python code here..."
998
+ )
999
 
1000
+ autonomy_slider = gr.Slider(
1001
+ minimum=0,
1002
+ maximum=10,
1003
+ step=1,
1004
+ value=5,
1005
+ label="Autonomy Level",
1006
+ info="0: No fixes, 5: Balanced, 10: Fully autonomous"
1007
  )
1008
+
1009
+ execute_btn = gr.Button("Execute Code", variant="primary")
1010
+
1011
+ output_json = gr.JSON(label="Execution Result")
1012
+
1013
+ execute_btn.click(
1014
+ fn=process_code,
1015
+ inputs=[code_input, autonomy_slider],
1016
+ outputs=output_json
1017
  )
1018
+
1019
+ with gr.Tab("Settings"):
1020
+ gr.Markdown("""
1021
+ ### Configuration
1022
+ - Model: bigcode/starcoder
1023
+ - Embedding Model: sentence-transformers/all-mpnet-base-v2
1024
+ - Temperature: 0.1
1025
+ - Max Length: 2048
1026
+ """)
1027
+
1028
+ with gr.Tab("Help"):
1029
+ gr.Markdown("""
1030
+ ### How to Use
1031
+ 1. Enter your Python code in the Code Input area
1032
+ 2. Adjust the Autonomy Level:
1033
+ - 0: No automatic fixes
1034
+ - 5: Balanced approach
1035
+ - 10: Fully autonomous operation
1036
+ 3. Click "Execute Code" to run
1037
+
1038
+ ### Features
1039
+ - Automatic code analysis
1040
+ - Error detection and fixing
1041
+ - Code formatting
1042
+ - Syntax validation
1043
+ """)
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
1074
+ flask_thread = threading.Thread(target=run_flask, daemon=True)
1075
+ gradio_thread = threading.Thread(target=run_gradio, daemon=True)
1076
+
1077
+ flask_thread.start()
1078
+ gradio_thread.start()
1079
+
1080
+ # Keep the main thread alive
1081
+ try:
1082
+ while True:
1083
+ time.sleep(1)
1084
+ except KeyboardInterrupt:
1085
+ print("Shutting down...")
1086
  class ChatState:
1087
  def __init__(self):
1088
  self.current_step = 0