npc0 commited on
Commit
0f91692
·
verified ·
1 Parent(s): 4581d8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -99
app.py CHANGED
@@ -11,104 +11,127 @@ import zipfile
11
  # f.write(os.environ['METAGPT_CONFIG_WITH_ANTHROPIC_API'])
12
 
13
  st.title("AI Software Coder")
14
- text_input = st.text_area("Enter your software development requirements here:")
15
-
16
- # def generate_zip(files):
17
- # """Generates a zip file containing the input files."""
18
- # zip_buffer = io.BytesIO()
19
- # with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
20
- # for filename, file_content in files.items():
21
- # zip_file.writestr(filename, file_content)
22
- # zip_buffer.seek(0)
23
- # return zip_buffer
24
-
25
- # st.title("AI Software Coder")
26
- # text_input = st.text_area("Enter your software development requirements here:",
27
- # value="""The goal.
28
-
29
- # The instructions of the task for each file example, things to do with input and output.
30
-
31
- # Here are some examples.
32
-
33
- # <example>
34
- # ### filename.json
35
- # Original document:
36
- # ```markdown
37
- # ## policy title
38
- # detailed section
39
- # - blah blah
40
- # ```
41
-
42
- # Configuration:
43
- # ```json
44
- # {
45
- # "income_limit": 50
46
- # }
47
- # ```
48
- # </example>
49
-
50
- # <example>
51
- # ### filename.py
52
- # Original document:
53
- # ```markdown
54
- # ## policy title
55
- # detailed section
56
- # - blah blah
57
- # ```
58
-
59
- # Configuration:
60
- # ```py
61
- # class AgeCalculator:
62
- # def __init__(self, birth_year):
63
- # self.birth_year = birth_year
64
-
65
- # def calculate_age(self, current_year):
66
- # age = current_year - self.birth_year
67
- # return self._validate_and_format_age(age)
68
-
69
- # def _validate_and_format_age(self, age):
70
- # if age < 0:
71
- # raise ValueError("Invalid age calculated")
72
- # return f"User is {age} years old"
73
-
74
- # def get_user_age(birth_year, current_year):
75
- # calculator = AgeCalculator(birth_year)
76
- # return calculator.calculate_age(current_year)
77
- # ```
78
- # </example>
79
-
80
- # Here is the additional input from a lawer:
81
-
82
- # <input>
83
- # comments from Nick/Marc/...
84
- # </input>
85
- # """)
86
-
87
- # if st.button("Generate Code"):
88
- # with open(CONFIG_FILE_PATH) as f:
89
- # st.write(f.read())
90
- # # def download_content(url):
91
- # # response = requests.get(url)
92
- # # response.raise_for_status()
93
- # # return response.text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
- # # def replace_urls_with_content(text):
96
- # # lines = text.splitlines()
97
- # # for i, line in enumerate(lines):
98
- # # if line.startswith('http://') or line.startswith('https://'):
99
- # # try:
100
- # # content = download_content(line)
101
- # # lines[i] = line.split('/')[-1] + '\n```\n' + content + '\n```'
102
- # # except requests.exceptions.RequestException as e:
103
- # # print(f"Error downloading content from {line}: {e}")
104
- # # return '\n'.join(lines)
105
 
106
- # # text_input = replace_urls_with_content(text_input)
107
- # # repo: ProjectRepo = generate_repo(text_input)
108
- # # zip_buffer = generate_zip(repo.all_files)
109
- # # st.download_button(
110
- # # label="Download Code Repository",
111
- # # data=zip_buffer,
112
- # # file_name="output.zip",
113
- # # mime="application/zip"
114
- # # )
 
 
11
  # f.write(os.environ['METAGPT_CONFIG_WITH_ANTHROPIC_API'])
12
 
13
  st.title("AI Software Coder")
14
+ def check_password():
15
+ """Returns `True` if the user had the correct password."""
16
+
17
+ def password_entered():
18
+ """Checks whether a password entered by the user is correct."""
19
+ if hmac.compare_digest(st.session_state["password"], os.environ['PAGE_PASSWORD']):
20
+ st.session_state["password_correct"] = True
21
+ del st.session_state["password"] # Don't store the password.
22
+ else:
23
+ st.session_state["password_correct"] = False
24
+
25
+ # Return True if the password is validated.
26
+ if st.session_state.get("password_correct", False):
27
+ return True
28
+
29
+ # Show input for password.
30
+ st.text_input(
31
+ "Password", type="password", on_change=password_entered, key="password"
32
+ )
33
+ if "password_correct" in st.session_state:
34
+ st.error("😕 Password incorrect")
35
+ return False
36
+
37
+
38
+ if not check_password():
39
+ st.stop() # Do not continue if check_password is not True.
40
+
41
+ def generate_zip(files):
42
+ """Generates a zip file containing the input files."""
43
+ zip_buffer = io.BytesIO()
44
+ with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
45
+ for filename, file_content in files.items():
46
+ zip_file.writestr(filename, file_content)
47
+ zip_buffer.seek(0)
48
+ return zip_buffer
49
+
50
+ text_input = st.text_area("Enter your software development requirements here:",
51
+ value="""The goal.
52
+
53
+ The instructions of the task for each file example, things to do with input and output.
54
+
55
+ Here are some examples.
56
+
57
+ <example>
58
+ ### filename.json
59
+ Original document:
60
+ ```markdown
61
+ ## policy title
62
+ detailed section
63
+ - blah blah
64
+ ```
65
+
66
+ Configuration:
67
+ ```json
68
+ {
69
+ "income_limit": 50
70
+ }
71
+ ```
72
+ </example>
73
+
74
+ <example>
75
+ ### filename.py
76
+ Original document:
77
+ ```markdown
78
+ ## policy title
79
+ detailed section
80
+ - blah blah
81
+ ```
82
+
83
+ Configuration:
84
+ ```py
85
+ class AgeCalculator:
86
+ def __init__(self, birth_year):
87
+ self.birth_year = birth_year
88
+
89
+ def calculate_age(self, current_year):
90
+ age = current_year - self.birth_year
91
+ return self._validate_and_format_age(age)
92
+
93
+ def _validate_and_format_age(self, age):
94
+ if age < 0:
95
+ raise ValueError("Invalid age calculated")
96
+ return f"User is {age} years old"
97
+
98
+ def get_user_age(birth_year, current_year):
99
+ calculator = AgeCalculator(birth_year)
100
+ return calculator.calculate_age(current_year)
101
+ ```
102
+ </example>
103
+
104
+ Here is the additional input from a lawer:
105
+
106
+ <input>
107
+ comments from Nick/Marc/...
108
+ </input>
109
+ """)
110
+
111
+ if st.button("Generate Code"):
112
+ # def download_content(url):
113
+ # response = requests.get(url)
114
+ # response.raise_for_status()
115
+ # return response.text
116
 
117
+ # def replace_urls_with_content(text):
118
+ # lines = text.splitlines()
119
+ # for i, line in enumerate(lines):
120
+ # if line.startswith('http://') or line.startswith('https://'):
121
+ # try:
122
+ # content = download_content(line)
123
+ # lines[i] = line.split('/')[-1] + '\n```\n' + content + '\n```'
124
+ # except requests.exceptions.RequestException as e:
125
+ # print(f"Error downloading content from {line}: {e}")
126
+ # return '\n'.join(lines)
127
 
128
+ # text_input = replace_urls_with_content(text_input)
129
+ # repo: ProjectRepo = generate_repo(text_input)
130
+ # zip_buffer = generate_zip(repo.all_files)
131
+ # st.download_button(
132
+ # label="Download Code Repository",
133
+ # data=zip_buffer,
134
+ # file_name="output.zip",
135
+ # mime="application/zip"
136
+ # )
137
+ st.balloons()