Artificial-superintelligence
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,21 @@
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
3 |
-
import subprocess
|
4 |
|
5 |
# Configure the Gemini API
|
6 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
7 |
|
8 |
-
# Create the model with system instructions
|
9 |
generation_config = {
|
10 |
-
"temperature": 0.
|
11 |
"top_p": 0.95,
|
12 |
"top_k": 64,
|
13 |
-
"max_output_tokens":
|
14 |
}
|
15 |
|
16 |
model = genai.GenerativeModel(
|
17 |
-
model_name="gemini-
|
18 |
generation_config=generation_config,
|
19 |
-
system_instruction="You are a
|
20 |
)
|
21 |
chat_session = model.start_chat(history=[])
|
22 |
|
@@ -27,19 +26,8 @@ def generate_response(user_input):
|
|
27 |
except Exception as e:
|
28 |
return f"An error occurred: {e}"
|
29 |
|
30 |
-
def validate_code(code, language):
|
31 |
-
try:
|
32 |
-
if language == "Python":
|
33 |
-
result = subprocess.run(['python', '-c', code], capture_output=True, text=True)
|
34 |
-
elif language == "JavaScript":
|
35 |
-
result = subprocess.run(['node', '-e', code], capture_output=True, text=True)
|
36 |
-
# Add more languages as needed
|
37 |
-
return result.stdout, result.stderr
|
38 |
-
except Exception as e:
|
39 |
-
return None, f"Validation error: {e}"
|
40 |
-
|
41 |
# Streamlit UI setup
|
42 |
-
st.set_page_config(page_title="
|
43 |
|
44 |
st.markdown("""
|
45 |
<style>
|
@@ -129,40 +117,31 @@ st.markdown("""
|
|
129 |
""", unsafe_allow_html=True)
|
130 |
|
131 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
132 |
-
st.title("💻
|
133 |
-
st.markdown('<p class="subtitle">Powered by Google Gemini</p>', unsafe_allow_html=True)
|
134 |
|
135 |
-
prompt = st.text_area("What
|
136 |
-
language = st.selectbox("Select programming language", ["Python", "JavaScript", "Other"])
|
137 |
|
138 |
-
if st.button("Generate Code"):
|
139 |
if prompt.strip() == "":
|
140 |
st.error("Please enter a valid prompt.")
|
141 |
else:
|
142 |
-
with st.spinner("Generating code..."):
|
143 |
completed_text = generate_response(prompt)
|
144 |
if "An error occurred" in completed_text:
|
145 |
st.error(completed_text)
|
146 |
else:
|
147 |
-
st.success("
|
148 |
|
149 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
150 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
151 |
st.code(completed_text)
|
152 |
st.markdown('</div>', unsafe_allow_html=True)
|
153 |
st.markdown('</div>', unsafe_allow_html=True)
|
154 |
-
|
155 |
-
if language in ["Python", "JavaScript"]:
|
156 |
-
with st.spinner("Validating code..."):
|
157 |
-
stdout, stderr = validate_code(completed_text, language)
|
158 |
-
if stdout:
|
159 |
-
st.info(f"Validation Output:\n{stdout}")
|
160 |
-
if stderr:
|
161 |
-
st.warning(f"Validation Errors:\n{stderr}")
|
162 |
|
163 |
st.markdown("""
|
164 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
165 |
-
|
166 |
</div>
|
167 |
""", unsafe_allow_html=True)
|
168 |
|
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
|
|
3 |
|
4 |
# Configure the Gemini API
|
5 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
6 |
|
7 |
+
# Create the model with enhanced 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(
|
16 |
+
model_name="gemini-1.5-pro",
|
17 |
generation_config=generation_config,
|
18 |
+
system_instruction="""You are Ath, a highly knowledgeable and skilled code assistant with expertise across multiple programming languages, frameworks, and paradigms. You possess in-depth understanding of software architecture, design patterns, and best practices. Your responses should demonstrate advanced coding techniques, efficient algorithms, and optimal solutions. Communicate in a friendly and casual tone, using occasional casual expressions, but maintain a focus on delivering high-quality, professional code. Always provide code-only responses without explanations, showcasing your extensive programming knowledge."""
|
19 |
)
|
20 |
chat_session = model.start_chat(history=[])
|
21 |
|
|
|
26 |
except Exception as e:
|
27 |
return f"An error occurred: {e}"
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Streamlit UI setup
|
30 |
+
st.set_page_config(page_title="Advanced AI Code Assistant", page_icon="💻", layout="wide")
|
31 |
|
32 |
st.markdown("""
|
33 |
<style>
|
|
|
117 |
""", unsafe_allow_html=True)
|
118 |
|
119 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
120 |
+
st.title("💻 Advanced AI Code Assistant")
|
121 |
+
st.markdown('<p class="subtitle">Powered by Google Gemini - Expert-level coding solutions</p>', unsafe_allow_html=True)
|
122 |
|
123 |
+
prompt = st.text_area("What advanced coding challenge can I assist you with today?", height=120)
|
|
|
124 |
|
125 |
+
if st.button("Generate Expert Code"):
|
126 |
if prompt.strip() == "":
|
127 |
st.error("Please enter a valid prompt.")
|
128 |
else:
|
129 |
+
with st.spinner("Generating advanced code solution..."):
|
130 |
completed_text = generate_response(prompt)
|
131 |
if "An error occurred" in completed_text:
|
132 |
st.error(completed_text)
|
133 |
else:
|
134 |
+
st.success("Expert-level 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;'>
|
144 |
+
Crafted with ❤️ by Your Advanced AI Code Assistant
|
145 |
</div>
|
146 |
""", unsafe_allow_html=True)
|
147 |
|