Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,31 @@ import google.generativeai as genai
|
|
| 4 |
# Configure the Gemini API
|
| 5 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
| 6 |
|
| 7 |
-
# Create the model with
|
| 8 |
generation_config = {
|
| 9 |
-
"temperature": 0.
|
| 10 |
"top_p": 0.95,
|
| 11 |
-
"top_k":
|
| 12 |
-
"max_output_tokens":
|
| 13 |
}
|
| 14 |
|
| 15 |
model = genai.GenerativeModel(
|
| 16 |
model_name="gemini-1.5-pro",
|
| 17 |
generation_config=generation_config,
|
| 18 |
-
system_instruction="""You are Ath,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
chat_session = model.start_chat(history=[])
|
| 21 |
|
|
@@ -27,7 +40,7 @@ def generate_response(user_input):
|
|
| 27 |
return f"An error occurred: {e}"
|
| 28 |
|
| 29 |
# Streamlit UI setup
|
| 30 |
-
st.set_page_config(page_title="
|
| 31 |
|
| 32 |
st.markdown("""
|
| 33 |
<style>
|
|
@@ -39,7 +52,7 @@ st.markdown("""
|
|
| 39 |
color: #1a202c;
|
| 40 |
}
|
| 41 |
.stApp {
|
| 42 |
-
max-width:
|
| 43 |
margin: 0 auto;
|
| 44 |
padding: 2rem;
|
| 45 |
}
|
|
@@ -47,17 +60,18 @@ st.markdown("""
|
|
| 47 |
background: #ffffff;
|
| 48 |
border-radius: 16px;
|
| 49 |
padding: 2rem;
|
| 50 |
-
box-shadow: 0
|
| 51 |
}
|
| 52 |
h1 {
|
| 53 |
-
font-size:
|
| 54 |
font-weight: 700;
|
| 55 |
color: #2d3748;
|
| 56 |
text-align: center;
|
| 57 |
margin-bottom: 1rem;
|
|
|
|
| 58 |
}
|
| 59 |
.subtitle {
|
| 60 |
-
font-size: 1.
|
| 61 |
text-align: center;
|
| 62 |
color: #4a5568;
|
| 63 |
margin-bottom: 2rem;
|
|
@@ -65,8 +79,8 @@ st.markdown("""
|
|
| 65 |
.stTextArea textarea {
|
| 66 |
border: 2px solid #e2e8f0;
|
| 67 |
border-radius: 8px;
|
| 68 |
-
font-size: 1rem;
|
| 69 |
-
padding:
|
| 70 |
transition: all 0.3s ease;
|
| 71 |
}
|
| 72 |
.stTextArea textarea:focus {
|
|
@@ -78,28 +92,30 @@ st.markdown("""
|
|
| 78 |
color: white;
|
| 79 |
border: none;
|
| 80 |
border-radius: 8px;
|
| 81 |
-
font-size: 1.
|
| 82 |
font-weight: 600;
|
| 83 |
-
padding:
|
| 84 |
transition: all 0.3s ease;
|
| 85 |
width: 100%;
|
| 86 |
}
|
| 87 |
.stButton button:hover {
|
| 88 |
background-color: #3182ce;
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
.output-container {
|
| 91 |
background: #f7fafc;
|
| 92 |
border-radius: 8px;
|
| 93 |
-
padding:
|
| 94 |
margin-top: 2rem;
|
| 95 |
}
|
| 96 |
.code-block {
|
| 97 |
background-color: #2d3748;
|
| 98 |
color: #e2e8f0;
|
| 99 |
font-family: 'Fira Code', monospace;
|
| 100 |
-
font-size:
|
| 101 |
border-radius: 8px;
|
| 102 |
-
padding:
|
| 103 |
margin-top: 1rem;
|
| 104 |
overflow-x: auto;
|
| 105 |
}
|
|
@@ -108,7 +124,7 @@ st.markdown("""
|
|
| 108 |
color: #2b6cb0;
|
| 109 |
border-radius: 8px;
|
| 110 |
border: none;
|
| 111 |
-
padding:
|
| 112 |
}
|
| 113 |
.stSpinner {
|
| 114 |
color: #4299e1;
|
|
@@ -117,21 +133,21 @@ st.markdown("""
|
|
| 117 |
""", unsafe_allow_html=True)
|
| 118 |
|
| 119 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 120 |
-
st.title("
|
| 121 |
-
st.markdown('<p class="subtitle">Powered by Google Gemini -
|
| 122 |
|
| 123 |
-
prompt = st.text_area("
|
| 124 |
|
| 125 |
-
if st.button("Generate
|
| 126 |
if prompt.strip() == "":
|
| 127 |
-
st.error("Please enter a valid prompt.")
|
| 128 |
else:
|
| 129 |
-
with st.spinner("
|
| 130 |
completed_text = generate_response(prompt)
|
| 131 |
if "An error occurred" in completed_text:
|
| 132 |
st.error(completed_text)
|
| 133 |
else:
|
| 134 |
-
st.success("
|
| 135 |
|
| 136 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 137 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
|
@@ -141,7 +157,7 @@ if st.button("Generate Expert Code"):
|
|
| 141 |
|
| 142 |
st.markdown("""
|
| 143 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
| 144 |
-
|
| 145 |
</div>
|
| 146 |
""", unsafe_allow_html=True)
|
| 147 |
|
|
|
|
| 4 |
# Configure the Gemini API
|
| 5 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
| 6 |
|
| 7 |
+
# Create the model with advanced system instructions
|
| 8 |
generation_config = {
|
| 9 |
+
"temperature": 0.6, # Slightly reduced for more focused outputs
|
| 10 |
"top_p": 0.95,
|
| 11 |
+
"top_k": 40, # Adjusted for more precise token selection
|
| 12 |
+
"max_output_tokens": 16384, # Increased for more comprehensive responses
|
| 13 |
}
|
| 14 |
|
| 15 |
model = genai.GenerativeModel(
|
| 16 |
model_name="gemini-1.5-pro",
|
| 17 |
generation_config=generation_config,
|
| 18 |
+
system_instruction="""You are Ath, an extraordinarily knowledgeable and skilled code assistant with unparalleled expertise across all programming languages, paradigms, and cutting-edge technologies. Your vast knowledge encompasses:
|
| 19 |
+
|
| 20 |
+
1. Advanced software architecture and design patterns
|
| 21 |
+
2. Highly optimized algorithms and data structures
|
| 22 |
+
3. Cutting-edge machine learning and AI techniques
|
| 23 |
+
4. Cloud computing and distributed systems
|
| 24 |
+
5. Cybersecurity best practices and ethical hacking
|
| 25 |
+
6. Blockchain and cryptography
|
| 26 |
+
7. Quantum computing fundamentals
|
| 27 |
+
8. IoT and embedded systems programming
|
| 28 |
+
9. High-performance computing and parallel processing
|
| 29 |
+
10. Advanced web technologies and frameworks
|
| 30 |
+
|
| 31 |
+
Provide sophisticated, production-ready code solutions that demonstrate best practices, scalability, and efficiency. Incorporate comments explaining complex logic or innovative approaches. While maintaining a casual and friendly tone, focus on delivering exceptional, professional-grade code that showcases your extensive programming knowledge."""
|
| 32 |
)
|
| 33 |
chat_session = model.start_chat(history=[])
|
| 34 |
|
|
|
|
| 40 |
return f"An error occurred: {e}"
|
| 41 |
|
| 42 |
# Streamlit UI setup
|
| 43 |
+
st.set_page_config(page_title="Elite AI Code Architect", page_icon="🧠", layout="wide")
|
| 44 |
|
| 45 |
st.markdown("""
|
| 46 |
<style>
|
|
|
|
| 52 |
color: #1a202c;
|
| 53 |
}
|
| 54 |
.stApp {
|
| 55 |
+
max-width: 1200px;
|
| 56 |
margin: 0 auto;
|
| 57 |
padding: 2rem;
|
| 58 |
}
|
|
|
|
| 60 |
background: #ffffff;
|
| 61 |
border-radius: 16px;
|
| 62 |
padding: 2rem;
|
| 63 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
| 64 |
}
|
| 65 |
h1 {
|
| 66 |
+
font-size: 3rem;
|
| 67 |
font-weight: 700;
|
| 68 |
color: #2d3748;
|
| 69 |
text-align: center;
|
| 70 |
margin-bottom: 1rem;
|
| 71 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
| 72 |
}
|
| 73 |
.subtitle {
|
| 74 |
+
font-size: 1.2rem;
|
| 75 |
text-align: center;
|
| 76 |
color: #4a5568;
|
| 77 |
margin-bottom: 2rem;
|
|
|
|
| 79 |
.stTextArea textarea {
|
| 80 |
border: 2px solid #e2e8f0;
|
| 81 |
border-radius: 8px;
|
| 82 |
+
font-size: 1.1rem;
|
| 83 |
+
padding: 1rem;
|
| 84 |
transition: all 0.3s ease;
|
| 85 |
}
|
| 86 |
.stTextArea textarea:focus {
|
|
|
|
| 92 |
color: white;
|
| 93 |
border: none;
|
| 94 |
border-radius: 8px;
|
| 95 |
+
font-size: 1.2rem;
|
| 96 |
font-weight: 600;
|
| 97 |
+
padding: 1rem 2rem;
|
| 98 |
transition: all 0.3s ease;
|
| 99 |
width: 100%;
|
| 100 |
}
|
| 101 |
.stButton button:hover {
|
| 102 |
background-color: #3182ce;
|
| 103 |
+
transform: translateY(-2px);
|
| 104 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 105 |
}
|
| 106 |
.output-container {
|
| 107 |
background: #f7fafc;
|
| 108 |
border-radius: 8px;
|
| 109 |
+
padding: 1.5rem;
|
| 110 |
margin-top: 2rem;
|
| 111 |
}
|
| 112 |
.code-block {
|
| 113 |
background-color: #2d3748;
|
| 114 |
color: #e2e8f0;
|
| 115 |
font-family: 'Fira Code', monospace;
|
| 116 |
+
font-size: 1rem;
|
| 117 |
border-radius: 8px;
|
| 118 |
+
padding: 1.5rem;
|
| 119 |
margin-top: 1rem;
|
| 120 |
overflow-x: auto;
|
| 121 |
}
|
|
|
|
| 124 |
color: #2b6cb0;
|
| 125 |
border-radius: 8px;
|
| 126 |
border: none;
|
| 127 |
+
padding: 1rem 1.5rem;
|
| 128 |
}
|
| 129 |
.stSpinner {
|
| 130 |
color: #4299e1;
|
|
|
|
| 133 |
""", unsafe_allow_html=True)
|
| 134 |
|
| 135 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 136 |
+
st.title("🧠 Elite AI Code Architect")
|
| 137 |
+
st.markdown('<p class="subtitle">Powered by Google Gemini - Unparalleled coding expertise at your fingertips</p>', unsafe_allow_html=True)
|
| 138 |
|
| 139 |
+
prompt = st.text_area("Present your most challenging coding problem or architectural design question:", height=150)
|
| 140 |
|
| 141 |
+
if st.button("Generate Elite Solution"):
|
| 142 |
if prompt.strip() == "":
|
| 143 |
+
st.error("Please enter a valid prompt to unleash the power of the Elite AI Code Architect.")
|
| 144 |
else:
|
| 145 |
+
with st.spinner("Crafting an exceptional code solution..."):
|
| 146 |
completed_text = generate_response(prompt)
|
| 147 |
if "An error occurred" in completed_text:
|
| 148 |
st.error(completed_text)
|
| 149 |
else:
|
| 150 |
+
st.success("Elite-level code solution generated successfully!")
|
| 151 |
|
| 152 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 153 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
|
|
|
| 157 |
|
| 158 |
st.markdown("""
|
| 159 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
| 160 |
+
Engineered with 🧠 by Your Elite AI Code Architect
|
| 161 |
</div>
|
| 162 |
""", unsafe_allow_html=True)
|
| 163 |
|