nniehaus commited on
Commit
ace2951
·
verified ·
1 Parent(s): 9dc3e0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -3,14 +3,14 @@ import streamlit as st
3
  from tenacity import retry, stop_after_attempt, wait_fixed
4
 
5
  # Assuming the OpenAI API key is stored in Streamlit's secrets
6
- openai.api_key = st.secrets["YOUR_OPENAI_API_KEY"]
7
 
8
  st.title("Website Feature Code Generator")
9
 
10
  # User inputs for the feature they want to add
11
  feature_description = st.text_area(
12
  "Describe the website feature you'd like to implement:",
13
- "E.g., A contact form with name, email, and message fields that emails the site owner."
14
  )
15
 
16
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
@@ -23,15 +23,25 @@ def call_openai_api(feature_description):
23
  {"role": "user", "content": feature_description}
24
  ],
25
  )
 
 
 
26
  return response.choices[0].message['content']
27
  except Exception as e:
28
  st.error(f"An error occurred: {str(e)}")
29
  return None
30
 
31
  if st.button("Generate Code"):
32
- prompt = f"Write the HTML, CSS, and JavaScript code for a website feature described as follows: {feature_description}"
33
- code = call_openai_api(prompt)
34
  if code:
35
- st.code(code, language="html")
 
 
 
 
 
 
 
 
36
  else:
37
  st.write("Could not generate the code. Please check the feature description and try again.")
 
3
  from tenacity import retry, stop_after_attempt, wait_fixed
4
 
5
  # Assuming the OpenAI API key is stored in Streamlit's secrets
6
+ openai.api_key = st.secrets["OPENAI_API_KEY"]
7
 
8
  st.title("Website Feature Code Generator")
9
 
10
  # User inputs for the feature they want to add
11
  feature_description = st.text_area(
12
  "Describe the website feature you'd like to implement:",
13
+ placeholder="E.g., A contact form with name, email, and message fields that emails the site owner."
14
  )
15
 
16
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
 
23
  {"role": "user", "content": feature_description}
24
  ],
25
  )
26
+ # Prepare a prompt that asks for structured code with clear instructions
27
+ prompt = f"Generate structured code (HTML, CSS, JavaScript) for the website feature described: '{feature_description}'. " \
28
+ "Include comments to guide someone on where to place each part of the code in their website."
29
  return response.choices[0].message['content']
30
  except Exception as e:
31
  st.error(f"An error occurred: {str(e)}")
32
  return None
33
 
34
  if st.button("Generate Code"):
35
+ code = call_openai_api(feature_description)
 
36
  if code:
37
+ # Display the generated code with instructions
38
+ st.subheader("Generated Code and Instructions")
39
+ st.text(code)
40
+ st.markdown("""
41
+ **Instructions:**
42
+ - Copy the **HTML** section and paste it into the body of your HTML file where you want the feature to appear.
43
+ - Copy the **CSS** section and paste it into your CSS file or within the `<style>` tag in the `<head>` section of your HTML.
44
+ - Copy the **JavaScript** section and paste it before the closing `</body>` tag of your HTML, preferably in a separate JavaScript file linked to your HTML.
45
+ """)
46
  else:
47
  st.write("Could not generate the code. Please check the feature description and try again.")