Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
config = agent.generate_project_config(project_description)
|
34 |
-
|
35 |
-
except Exception as e:
|
36 |
-
logger.error(f"Error generating project config: {str(e)}")
|
37 |
-
return jsonify({"error": str(e)}), 400
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
config_dict =
|
43 |
config = ProjectConfig(**config_dict)
|
44 |
structure = agent.create_project_structure(config)
|
45 |
-
|
46 |
-
except Exception as e:
|
47 |
-
logger.error(f"Error creating project structure: {str(e)}")
|
48 |
-
return jsonify({"error": str(e)}), 400
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
existing_code = request.json.get('existing_code')
|
55 |
new_code = agent.implement_feature(feature_description, existing_code)
|
56 |
-
|
57 |
-
except Exception as e:
|
58 |
-
logger.error(f"Error implementing feature: {str(e)}")
|
59 |
-
return jsonify({"error": str(e)}), 400
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
code = request.json['code']
|
65 |
review = agent.review_code(code)
|
66 |
-
|
67 |
-
except Exception as e:
|
68 |
-
logger.error(f"Error reviewing code: {str(e)}")
|
69 |
-
return jsonify({"error": str(e)}), 400
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
optimization_goal = request.json['optimization_goal']
|
76 |
optimized_code = agent.optimize_code(code, optimization_goal)
|
77 |
-
|
78 |
-
except Exception as e:
|
79 |
-
logger.error(f"Error optimizing code: {str(e)}")
|
80 |
-
return jsonify({"error": str(e)}), 400
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
code = request.json['code']
|
86 |
documentation = agent.generate_documentation(code)
|
87 |
-
|
88 |
-
except Exception as e:
|
89 |
-
logger.error(f"Error generating documentation: {str(e)}")
|
90 |
-
return jsonify({"error": str(e)}), 400
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
code = request.json['code']
|
96 |
test_suggestions = agent.suggest_tests(code)
|
97 |
-
|
98 |
-
except Exception as e:
|
99 |
-
logger.error(f"Error suggesting tests: {str(e)}")
|
100 |
-
return jsonify({"error": str(e)}), 400
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
code = request.json['code']
|
106 |
explanation = agent.explain_code(code)
|
107 |
-
|
108 |
-
except Exception as e:
|
109 |
-
logger.error(f"Error explaining code: {str(e)}")
|
110 |
-
return jsonify({"error": str(e)}), 400
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
code = request.json['code']
|
116 |
refactoring_suggestions = agent.suggest_refactoring(code)
|
117 |
-
|
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)
|
|
|
|
|
|
|
|
|
|
|
|