Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,3 +33,57 @@ def generate_app(description, bot):
|
|
| 33 |
def refine_app(current_code, refinement, bot):
|
| 34 |
chat = ChatOpenAI(temperature=0.1, model_name="gpt-4", openai_api_key=OPENAI_API_KEY)
|
| 35 |
prompt = f"""@{bot} I have a Poe Canvas App that I want to refine. Here is the current code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def refine_app(current_code, refinement, bot):
|
| 34 |
chat = ChatOpenAI(temperature=0.1, model_name="gpt-4", openai_api_key=OPENAI_API_KEY)
|
| 35 |
prompt = f"""@{bot} I have a Poe Canvas App that I want to refine. Here is the current code:
|
| 36 |
+
|
| 37 |
+
I want to make the following changes:
|
| 38 |
+
"{refinement}"
|
| 39 |
+
|
| 40 |
+
Please provide an updated version of the code that implements these changes. Keep the core functionality and only modify what's necessary.
|
| 41 |
+
|
| 42 |
+
Your response should follow this format:
|
| 43 |
+
|
| 44 |
+
1. A brief explanation of what changes you've made
|
| 45 |
+
2. A Markdown code block containing the complete updated HTML/CSS/JS for the app"""
|
| 46 |
+
return chat.chat(messages_from_template(prompt))
|
| 47 |
+
|
| 48 |
+
def main():
|
| 49 |
+
st.title("App Creator AI")
|
| 50 |
+
st.header("Create and refine your web applications")
|
| 51 |
+
|
| 52 |
+
# App Description Input
|
| 53 |
+
with st.expander("1. App Description"):
|
| 54 |
+
description = st.text_area(
|
| 55 |
+
"Describe the app you want to create",
|
| 56 |
+
placeholder="Describe the app you want to create in detail. For example: 'Create a to-do list app with the ability to add, remove, and mark tasks as complete. The app should have a clean design with a dark mode option.'"
|
| 57 |
+
)
|
| 58 |
+
bot = st.selectbox(
|
| 59 |
+
"AI Model",
|
| 60 |
+
["Claude-3.7-Sonnet", "GPT-4o", "GPT-4o-mini", "o3-mini"]
|
| 61 |
+
)
|
| 62 |
+
if st.button("Generate App"):
|
| 63 |
+
if not description:
|
| 64 |
+
st.error("Please enter a description of the app you want to create.")
|
| 65 |
+
return
|
| 66 |
+
result = generate_app(description, bot)
|
| 67 |
+
# Display result in a code block
|
| 68 |
+
st.markdown("```html\n" + result + "\n```")
|
| 69 |
+
|
| 70 |
+
# Results Section
|
| 71 |
+
with st.expander("2. Generated App"):
|
| 72 |
+
code = st.text_area("Generated Code")
|
| 73 |
+
if code:
|
| 74 |
+
# Show preview in a frame
|
| 75 |
+
st.components.html(code, height=500)
|
| 76 |
+
# Add copy button
|
| 77 |
+
if st.button("Copy Code"):
|
| 78 |
+
st.write(code)
|
| 79 |
+
|
| 80 |
+
# Refinement Section
|
| 81 |
+
with st.expander("3. Refine Your App"):
|
| 82 |
+
refinement = st.text_area("Enter refinements")
|
| 83 |
+
if refinement:
|
| 84 |
+
if st.button("Refine App"):
|
| 85 |
+
result = refine_app(code, refinement, bot)
|
| 86 |
+
st.markdown("```html\n" + result + "\n```")
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
main()
|