Artificial-superintelligence commited on
Commit
a7a2ad9
·
verified ·
1 Parent(s): e512f23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -6,10 +6,10 @@ genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
6
 
7
  # Create the model with system instructions
8
  generation_config = {
9
- "temperature": 1,
10
  "top_p": 0.95,
11
  "top_k": 64,
12
- "max_output_tokens": 8192,
13
  }
14
 
15
  model = genai.GenerativeModel(
@@ -20,8 +20,11 @@ model = genai.GenerativeModel(
20
  chat_session = model.start_chat(history=[])
21
 
22
  def generate_response(user_input):
23
- response = chat_session.send_message(user_input)
24
- return response.text
 
 
 
25
 
26
  # Streamlit UI setup
27
  st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="💻", layout="wide")
@@ -125,13 +128,16 @@ if st.button("Generate Code"):
125
  else:
126
  with st.spinner("Generating code..."):
127
  completed_text = generate_response(prompt)
128
- st.success("Code generated successfully!")
129
-
130
- st.markdown('<div class="output-container">', unsafe_allow_html=True)
131
- st.markdown('<div class="code-block">', unsafe_allow_html=True)
132
- st.code(completed_text)
133
- st.markdown('</div>', unsafe_allow_html=True)
134
- st.markdown('</div>', unsafe_allow_html=True)
 
 
 
135
 
136
  st.markdown("""
137
  <div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
 
6
 
7
  # Create the model with system instructions
8
  generation_config = {
9
+ "temperature": 0.7,
10
  "top_p": 0.95,
11
  "top_k": 64,
12
+ "max_output_tokens": 10240,
13
  }
14
 
15
  model = genai.GenerativeModel(
 
20
  chat_session = model.start_chat(history=[])
21
 
22
  def generate_response(user_input):
23
+ try:
24
+ response = chat_session.send_message(user_input)
25
+ return response.text
26
+ except Exception as e:
27
+ return f"An error occurred: {e}"
28
 
29
  # Streamlit UI setup
30
  st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="💻", layout="wide")
 
128
  else:
129
  with st.spinner("Generating code..."):
130
  completed_text = generate_response(prompt)
131
+ if "An error occurred" in completed_text:
132
+ st.error(completed_text)
133
+ else:
134
+ st.success("Code generated successfully!")
135
+
136
+ st.markdown('<div class="output-container">', unsafe_allow_html=True)
137
+ st.markdown('<div class="code-block">', unsafe_allow_html=True)
138
+ st.code(completed_text)
139
+ st.markdown('</div>', unsafe_allow_html=True)
140
+ st.markdown('</div>', unsafe_allow_html=True)
141
 
142
  st.markdown("""
143
  <div style='text-align: center; margin-top: 2rem; color: #4a5568;'>