acecalisto3 commited on
Commit
f382b4f
·
verified ·
1 Parent(s): 430480b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -89
app.py CHANGED
@@ -1,19 +1,11 @@
 
1
  import os
2
- import logging
3
- from flask import Flask, request, jsonify, render_template
4
  from dotenv import load_dotenv
5
  from supplemental import EnhancedAIAgent, ProjectConfig
6
 
7
  # Load environment variables
8
  load_dotenv()
9
 
10
- # Configure logging
11
- logging.basicConfig(level=logging.INFO)
12
- logger = logging.getLogger(__name__)
13
-
14
- # Initialize Flask app
15
- app = Flask(__name__)
16
-
17
  # Initialize EnhancedAIAgent
18
  agent = EnhancedAIAgent(
19
  name="WebDevMaster",
@@ -22,102 +14,79 @@ agent = EnhancedAIAgent(
22
  model_name="gpt2"
23
  )
24
 
25
- @app.route('/')
26
- def index():
27
- return render_template('index.html')
 
 
 
 
 
 
 
 
28
 
29
- @app.route('/generate_project_config', methods=['POST'])
30
- def generate_project_config():
31
- try:
32
- project_description = request.json['project_description']
 
 
 
 
 
 
33
  config = agent.generate_project_config(project_description)
34
- return jsonify(config.__dict__), 200
35
- except Exception as e:
36
- logger.error(f"Error generating project config: {str(e)}")
37
- return jsonify({"error": str(e)}), 400
38
 
39
- @app.route('/create_project_structure', methods=['POST'])
40
- def create_project_structure():
41
- try:
42
- config_dict = request.json
43
  config = ProjectConfig(**config_dict)
44
  structure = agent.create_project_structure(config)
45
- return jsonify(structure), 200
46
- except Exception as e:
47
- logger.error(f"Error creating project structure: {str(e)}")
48
- return jsonify({"error": str(e)}), 400
49
 
50
- @app.route('/implement_feature', methods=['POST'])
51
- def implement_feature():
52
- try:
53
- feature_description = request.json['feature_description']
54
- existing_code = request.json.get('existing_code')
55
  new_code = agent.implement_feature(feature_description, existing_code)
56
- return jsonify({"code": new_code}), 200
57
- except Exception as e:
58
- logger.error(f"Error implementing feature: {str(e)}")
59
- return jsonify({"error": str(e)}), 400
60
 
61
- @app.route('/review_code', methods=['POST'])
62
- def review_code():
63
- try:
64
- code = request.json['code']
65
  review = agent.review_code(code)
66
- return jsonify({"review": review}), 200
67
- except Exception as e:
68
- logger.error(f"Error reviewing code: {str(e)}")
69
- return jsonify({"error": str(e)}), 400
70
 
71
- @app.route('/optimize_code', methods=['POST'])
72
- def optimize_code():
73
- try:
74
- code = request.json['code']
75
- optimization_goal = request.json['optimization_goal']
76
  optimized_code = agent.optimize_code(code, optimization_goal)
77
- return jsonify({"optimized_code": optimized_code}), 200
78
- except Exception as e:
79
- logger.error(f"Error optimizing code: {str(e)}")
80
- return jsonify({"error": str(e)}), 400
81
 
82
- @app.route('/generate_documentation', methods=['POST'])
83
- def generate_documentation():
84
- try:
85
- code = request.json['code']
86
  documentation = agent.generate_documentation(code)
87
- return jsonify({"documentation": documentation}), 200
88
- except Exception as e:
89
- logger.error(f"Error generating documentation: {str(e)}")
90
- return jsonify({"error": str(e)}), 400
91
 
92
- @app.route('/suggest_tests', methods=['POST'])
93
- def suggest_tests():
94
- try:
95
- code = request.json['code']
96
  test_suggestions = agent.suggest_tests(code)
97
- return jsonify({"test_suggestions": test_suggestions}), 200
98
- except Exception as e:
99
- logger.error(f"Error suggesting tests: {str(e)}")
100
- return jsonify({"error": str(e)}), 400
101
 
102
- @app.route('/explain_code', methods=['POST'])
103
- def explain_code():
104
- try:
105
- code = request.json['code']
106
  explanation = agent.explain_code(code)
107
- return jsonify({"explanation": explanation}), 200
108
- except Exception as e:
109
- logger.error(f"Error explaining code: {str(e)}")
110
- return jsonify({"error": str(e)}), 400
111
 
112
- @app.route('/suggest_refactoring', methods=['POST'])
113
- def suggest_refactoring():
114
- try:
115
- code = request.json['code']
116
  refactoring_suggestions = agent.suggest_refactoring(code)
117
- return jsonify({"refactoring_suggestions": refactoring_suggestions}), 200
118
- except Exception as e:
119
- logger.error(f"Error suggesting refactoring: {str(e)}")
120
- return jsonify({"error": str(e)}), 400
121
-
122
- if __name__ == '__main__':
123
- app.run(debug=os.getenv('FLASK_DEBUG', 'False') == 'True', host='0.0.0.0', port=int(os.getenv('PORT', 5000)))
 
1
+ import streamlit as st
2
  import os
 
 
3
  from dotenv import load_dotenv
4
  from supplemental import EnhancedAIAgent, ProjectConfig
5
 
6
  # Load environment variables
7
  load_dotenv()
8
 
 
 
 
 
 
 
 
9
  # Initialize EnhancedAIAgent
10
  agent = EnhancedAIAgent(
11
  name="WebDevMaster",
 
14
  model_name="gpt2"
15
  )
16
 
17
+ st.title("EnhancedAIAgent Web Development Assistant")
18
+
19
+ st.write("""
20
+ This is a powerful AI-driven web development assistant that can help you with various tasks such as:
21
+ - Generating project configurations
22
+ - Creating project structures
23
+ - Implementing features
24
+ - Reviewing and optimizing code
25
+ - Generating documentation
26
+ - Suggesting tests and refactoring improvements
27
+ """)
28
 
29
+ option = st.selectbox(
30
+ "What would you like to do?",
31
+ ("Generate Project Config", "Create Project Structure", "Implement Feature",
32
+ "Review Code", "Optimize Code", "Generate Documentation",
33
+ "Suggest Tests", "Explain Code", "Suggest Refactoring")
34
+ )
35
+
36
+ if option == "Generate Project Config":
37
+ project_description = st.text_area("Enter project description:")
38
+ if st.button("Generate"):
39
  config = agent.generate_project_config(project_description)
40
+ st.json(config.__dict__)
 
 
 
41
 
42
+ elif option == "Create Project Structure":
43
+ config_json = st.text_area("Enter ProjectConfig JSON:")
44
+ if st.button("Create"):
45
+ config_dict = eval(config_json)
46
  config = ProjectConfig(**config_dict)
47
  structure = agent.create_project_structure(config)
48
+ st.json(structure)
 
 
 
49
 
50
+ elif option == "Implement Feature":
51
+ feature_description = st.text_area("Enter feature description:")
52
+ existing_code = st.text_area("Enter existing code (optional):")
53
+ if st.button("Implement"):
 
54
  new_code = agent.implement_feature(feature_description, existing_code)
55
+ st.code(new_code)
 
 
 
56
 
57
+ elif option == "Review Code":
58
+ code = st.text_area("Enter code to review:")
59
+ if st.button("Review"):
 
60
  review = agent.review_code(code)
61
+ st.write(review)
 
 
 
62
 
63
+ elif option == "Optimize Code":
64
+ code = st.text_area("Enter code to optimize:")
65
+ optimization_goal = st.text_input("Enter optimization goal:")
66
+ if st.button("Optimize"):
 
67
  optimized_code = agent.optimize_code(code, optimization_goal)
68
+ st.code(optimized_code)
 
 
 
69
 
70
+ elif option == "Generate Documentation":
71
+ code = st.text_area("Enter code to document:")
72
+ if st.button("Generate"):
 
73
  documentation = agent.generate_documentation(code)
74
+ st.markdown(documentation)
 
 
 
75
 
76
+ elif option == "Suggest Tests":
77
+ code = st.text_area("Enter code to suggest tests for:")
78
+ if st.button("Suggest"):
 
79
  test_suggestions = agent.suggest_tests(code)
80
+ st.write(test_suggestions)
 
 
 
81
 
82
+ elif option == "Explain Code":
83
+ code = st.text_area("Enter code to explain:")
84
+ if st.button("Explain"):
 
85
  explanation = agent.explain_code(code)
86
+ st.write(explanation)
 
 
 
87
 
88
+ elif option == "Suggest Refactoring":
89
+ code = st.text_area("Enter code to suggest refactoring:")
90
+ if st.button("Suggest"):
 
91
  refactoring_suggestions = agent.suggest_refactoring(code)
92
+ st.write(refactoring_suggestions)