Artificial-superintelligence commited on
Commit
98e1f97
·
verified ·
1 Parent(s): 838191d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import google.generativeai as genai
3
  import traceback
 
4
 
5
  # Configure the Gemini API with advanced error handling
6
  try:
@@ -11,10 +12,10 @@ except Exception as e:
11
 
12
  # Create the model with system instructions and advanced configuration
13
  generation_config = {
14
- "temperature": 0.5, # Lower temperature for more deterministic responses
15
- "top_p": 0.9,
16
- "top_k": 50,
17
- "max_output_tokens": 10240, # Increased max output tokens for longer responses
18
  }
19
 
20
  model = genai.GenerativeModel(
@@ -33,6 +34,16 @@ def generate_response(user_input):
33
  st.error(traceback.format_exc())
34
  return None
35
 
 
 
 
 
 
 
 
 
 
 
36
  # Streamlit UI setup
37
  st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="🚀", layout="wide")
38
 
@@ -160,6 +171,19 @@ for entry in st.session_state.history:
160
  st.markdown(f"**Assistant:**")
161
  st.code(entry['assistant'])
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  st.markdown("""
164
  <div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
165
  Created with ❤️ by Your Sleek AI Code Assistant
 
1
  import streamlit as st
2
  import google.generativeai as genai
3
  import traceback
4
+ import subprocess
5
 
6
  # Configure the Gemini API with advanced error handling
7
  try:
 
12
 
13
  # Create the model with system instructions and advanced configuration
14
  generation_config = {
15
+ "temperature": 0.3, # Lower temperature for more deterministic responses
16
+ "top_p": 0.85,
17
+ "top_k": 40,
18
+ "max_output_tokens": 12288, # Increased max output tokens for longer responses
19
  }
20
 
21
  model = genai.GenerativeModel(
 
34
  st.error(traceback.format_exc())
35
  return None
36
 
37
+ def execute_code(code):
38
+ try:
39
+ result = subprocess.run(['python', '-c', code], capture_output=True, text=True, timeout=10)
40
+ if result.returncode == 0:
41
+ return result.stdout
42
+ else:
43
+ return result.stderr
44
+ except Exception as e:
45
+ return f"An error occurred while executing code: {e}"
46
+
47
  # Streamlit UI setup
48
  st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="🚀", layout="wide")
49
 
 
171
  st.markdown(f"**Assistant:**")
172
  st.code(entry['assistant'])
173
 
174
+ # Interactive Code Execution
175
+ if st.session_state.history:
176
+ st.markdown("## Execute Code")
177
+ code_to_execute = st.selectbox("Select code to execute", [entry['assistant'] for entry in st.session_state.history])
178
+ if st.button("Execute Code"):
179
+ with st.spinner("Executing code..."):
180
+ execution_result = execute_code(code_to_execute)
181
+ st.markdown('<div class="output-container">', unsafe_allow_html=True)
182
+ st.markdown('<div class="code-block">', unsafe_allow_html=True)
183
+ st.code(execution_result)
184
+ st.markdown('</div>', unsafe_allow_html=True)
185
+ st.markdown('</div>', unsafe_allow_html=True)
186
+
187
  st.markdown("""
188
  <div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
189
  Created with ❤️ by Your Sleek AI Code Assistant