Spaces:
Sleeping
Sleeping
import os | |
import io | |
import requests | |
from metagpt.software_company import generate_repo, ProjectRepo | |
import streamlit as st | |
import zipfile | |
# CONFIG_FILE_PATH = '~/.metagpt/config2.yaml' | |
# if not os.path.exists(CONFIG_FILE_PATH): | |
# with open(CONFIG_FILE_PATH, 'w') as f: | |
# f.write(os.environ['METAGPT_CONFIG_WITH_ANTHROPIC_API']) | |
st.title("AI Software Coder") | |
text_input = st.text_area("Enter your software development requirements here:") | |
# def generate_zip(files): | |
# """Generates a zip file containing the input files.""" | |
# zip_buffer = io.BytesIO() | |
# with zipfile.ZipFile(zip_buffer, 'w') as zip_file: | |
# for filename, file_content in files.items(): | |
# zip_file.writestr(filename, file_content) | |
# zip_buffer.seek(0) | |
# return zip_buffer | |
# st.title("AI Software Coder") | |
# text_input = st.text_area("Enter your software development requirements here:", | |
# value="""The goal. | |
# The instructions of the task for each file example, things to do with input and output. | |
# Here are some examples. | |
# <example> | |
# ### filename.json | |
# Original document: | |
# ```markdown | |
# ## policy title | |
# detailed section | |
# - blah blah | |
# ``` | |
# Configuration: | |
# ```json | |
# { | |
# "income_limit": 50 | |
# } | |
# ``` | |
# </example> | |
# <example> | |
# ### filename.py | |
# Original document: | |
# ```markdown | |
# ## policy title | |
# detailed section | |
# - blah blah | |
# ``` | |
# Configuration: | |
# ```py | |
# class AgeCalculator: | |
# def __init__(self, birth_year): | |
# self.birth_year = birth_year | |
# def calculate_age(self, current_year): | |
# age = current_year - self.birth_year | |
# return self._validate_and_format_age(age) | |
# def _validate_and_format_age(self, age): | |
# if age < 0: | |
# raise ValueError("Invalid age calculated") | |
# return f"User is {age} years old" | |
# def get_user_age(birth_year, current_year): | |
# calculator = AgeCalculator(birth_year) | |
# return calculator.calculate_age(current_year) | |
# ``` | |
# </example> | |
# Here is the additional input from a lawer: | |
# <input> | |
# comments from Nick/Marc/... | |
# </input> | |
# """) | |
# if st.button("Generate Code"): | |
# with open(CONFIG_FILE_PATH) as f: | |
# st.write(f.read()) | |
# # def download_content(url): | |
# # response = requests.get(url) | |
# # response.raise_for_status() | |
# # return response.text | |
# # def replace_urls_with_content(text): | |
# # lines = text.splitlines() | |
# # for i, line in enumerate(lines): | |
# # if line.startswith('http://') or line.startswith('https://'): | |
# # try: | |
# # content = download_content(line) | |
# # lines[i] = line.split('/')[-1] + '\n```\n' + content + '\n```' | |
# # except requests.exceptions.RequestException as e: | |
# # print(f"Error downloading content from {line}: {e}") | |
# # return '\n'.join(lines) | |
# # text_input = replace_urls_with_content(text_input) | |
# # repo: ProjectRepo = generate_repo(text_input) | |
# # zip_buffer = generate_zip(repo.all_files) | |
# # st.download_button( | |
# # label="Download Code Repository", | |
# # data=zip_buffer, | |
# # file_name="output.zip", | |
# # mime="application/zip" | |
# # ) | |