Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import io
|
| 3 |
+
import requests
|
| 4 |
+
from metagpt.software_company import generate_repo, ProjectRepo
|
| 5 |
import streamlit as st
|
| 6 |
+
import zipfile
|
| 7 |
|
| 8 |
+
# CONFIG_FILE_PATH = '~/.metagpt/config2.yaml'
|
| 9 |
+
# if not os.path.exists(CONFIG_FILE_PATH):
|
| 10 |
+
# with open(CONFIG_FILE_PATH, 'w') as f:
|
| 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 |
+
# # )
|