File size: 4,590 Bytes
f382b4f
13a7a5d
c0311b6
 
67cab5d
6592a3f
 
 
 
c0311b6
 
 
 
6592a3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0311b6
 
 
 
 
 
13a7a5d
 
f382b4f
 
 
 
 
 
 
 
 
 
 
c0311b6
f382b4f
 
 
 
 
 
 
 
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
 
c0311b6
 
f382b4f
c0311b6
f382b4f
 
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
c0311b6
f382b4f
c0311b6
f382b4f
 
 
c0311b6
f382b4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import streamlit as st
import os
from dotenv import load_dotenv
from supplemental import EnhancedAIAgent, ProjectConfig
from json import JSONDecodeError  # Add this line to import JSONDecodeError
from transformers import pipeline

class JSONDecodeError(Exception):
    pass

# Load environment variables
load_dotenv()

class JSONDecodeError(Exception):
    pass

def generate_project_config(project_description):
    generator = pipeline('text-generation', model='gpt2')
    
    prompt = f"Generate a project configuration for the following project description: {project_description}\n\n{{"
    
    try:
        response = generator(prompt, max_length=500, num_return_sequences=1)
        generated_text = response[0]['generated_text']
        
        # Extract the JSON part
        json_start = generated_text.index('{')
        json_end = generated_text.rindex('}') + 1
        config_str = generated_text[json_start:json_end]
        
        config = json.loads(config_str)
        return config
    except JSONDecodeError as e:
        st.error(f"Error decoding JSON: {str(e)}")
        return None
    except Exception as e:
        st.error(f"An error occurred: {str(e)}")
        return None

st.title("Project Configuration Generator")

project_description = st.text_area("Enter your project description:")

if st.button("Generate Configuration"):
    if project_description:
        config = generate_project_config(project_description)
        if config:
            st.json(config)
    else:
        st.warning("Please enter a project description.")

# Initialize EnhancedAIAgent
agent = EnhancedAIAgent(
    name="WebDevMaster",
    description="Expert in full-stack web development",
    skills=["HTML", "CSS", "JavaScript", "React", "Node.js"],
    model_name="gpt2"
)

st.title("EnhancedAIAgent Web Development Assistant")

st.write("""
This is a powerful AI-driven web development assistant that can help you with various tasks such as:
- Generating project configurations
- Creating project structures
- Implementing features
- Reviewing and optimizing code
- Generating documentation
- Suggesting tests and refactoring improvements
""")

option = st.selectbox(
    "What would you like to do?",
    ("Generate Project Config", "Create Project Structure", "Implement Feature", 
     "Review Code", "Optimize Code", "Generate Documentation", 
     "Suggest Tests", "Explain Code", "Suggest Refactoring")
)

if option == "Generate Project Config":
    project_description = st.text_area("Enter project description:")
    if st.button("Generate"):
        config = agent.generate_project_config(project_description)
        st.json(config.__dict__)

elif option == "Create Project Structure":
    config_json = st.text_area("Enter ProjectConfig JSON:")
    if st.button("Create"):
        config_dict = eval(config_json)
        config = ProjectConfig(**config_dict)
        structure = agent.create_project_structure(config)
        st.json(structure)

elif option == "Implement Feature":
    feature_description = st.text_area("Enter feature description:")
    existing_code = st.text_area("Enter existing code (optional):")
    if st.button("Implement"):
        new_code = agent.implement_feature(feature_description, existing_code)
        st.code(new_code)

elif option == "Review Code":
    code = st.text_area("Enter code to review:")
    if st.button("Review"):
        review = agent.review_code(code)
        st.write(review)

elif option == "Optimize Code":
    code = st.text_area("Enter code to optimize:")
    optimization_goal = st.text_input("Enter optimization goal:")
    if st.button("Optimize"):
        optimized_code = agent.optimize_code(code, optimization_goal)
        st.code(optimized_code)

elif option == "Generate Documentation":
    code = st.text_area("Enter code to document:")
    if st.button("Generate"):
        documentation = agent.generate_documentation(code)
        st.markdown(documentation)

elif option == "Suggest Tests":
    code = st.text_area("Enter code to suggest tests for:")
    if st.button("Suggest"):
        test_suggestions = agent.suggest_tests(code)
        st.write(test_suggestions)

elif option == "Explain Code":
    code = st.text_area("Enter code to explain:")
    if st.button("Explain"):
        explanation = agent.explain_code(code)
        st.write(explanation)

elif option == "Suggest Refactoring":
    code = st.text_area("Enter code to suggest refactoring:")
    if st.button("Suggest"):
        refactoring_suggestions = agent.suggest_refactoring(code)
        st.write(refactoring_suggestions)