Spaces:
Runtime error
Runtime error
acecalisto3
commited on
Commit
•
12b3c93
1
Parent(s):
38e3e8b
Update app.py
Browse files
app.py
CHANGED
@@ -972,40 +972,117 @@ class GradioInterface:
|
|
972 |
generate_preview,
|
973 |
outputs=[preview_status]
|
974 |
)
|
975 |
-
def
|
976 |
-
"""Create
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
|
|
|
|
|
|
|
|
|
|
994 |
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
|
|
|
|
1000 |
)
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1004 |
)
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|