Update app.py
Browse files
app.py
CHANGED
@@ -4,31 +4,18 @@ 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 |
-
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,16 +27,16 @@ def generate_response(user_input):
|
|
40 |
return f"An error occurred: {e}"
|
41 |
|
42 |
# Streamlit UI setup
|
43 |
-
st.set_page_config(page_title="
|
44 |
|
45 |
st.markdown("""
|
46 |
<style>
|
47 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
48 |
|
49 |
body {
|
50 |
-
font-family: '
|
51 |
-
background-color: #
|
52 |
-
color: #
|
53 |
}
|
54 |
.stApp {
|
55 |
max-width: 1200px;
|
@@ -58,14 +45,14 @@ st.markdown("""
|
|
58 |
}
|
59 |
.main-container {
|
60 |
background: #ffffff;
|
61 |
-
border-radius:
|
62 |
-
padding:
|
63 |
-
box-shadow: 0
|
64 |
}
|
65 |
h1 {
|
66 |
font-size: 3rem;
|
67 |
font-weight: 700;
|
68 |
-
color: #
|
69 |
text-align: center;
|
70 |
margin-bottom: 1rem;
|
71 |
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
@@ -73,81 +60,101 @@ st.markdown("""
|
|
73 |
.subtitle {
|
74 |
font-size: 1.2rem;
|
75 |
text-align: center;
|
76 |
-
color: #
|
77 |
-
margin-bottom:
|
78 |
}
|
79 |
.stTextArea textarea {
|
80 |
-
border: 2px solid #
|
81 |
-
border-radius:
|
82 |
-
font-size:
|
83 |
padding: 1rem;
|
84 |
transition: all 0.3s ease;
|
|
|
85 |
}
|
86 |
.stTextArea textarea:focus {
|
87 |
-
border-color: #
|
88 |
-
box-shadow: 0 0 0 3px rgba(
|
89 |
}
|
90 |
.stButton button {
|
91 |
-
background-color: #
|
92 |
color: white;
|
93 |
border: none;
|
94 |
-
border-radius:
|
95 |
-
font-size: 1.
|
96 |
font-weight: 600;
|
97 |
-
padding:
|
98 |
transition: all 0.3s ease;
|
99 |
width: 100%;
|
|
|
100 |
}
|
101 |
.stButton button:hover {
|
102 |
-
background-color: #
|
103 |
transform: translateY(-2px);
|
104 |
-
box-shadow: 0
|
105 |
}
|
106 |
.output-container {
|
107 |
-
background: #
|
108 |
-
border-radius:
|
109 |
padding: 1.5rem;
|
110 |
margin-top: 2rem;
|
|
|
111 |
}
|
112 |
.code-block {
|
113 |
-
background-color: #
|
114 |
color: #e2e8f0;
|
115 |
font-family: 'Fira Code', monospace;
|
116 |
-
font-size:
|
117 |
-
border-radius:
|
118 |
padding: 1.5rem;
|
119 |
margin-top: 1rem;
|
120 |
overflow-x: auto;
|
121 |
}
|
122 |
.stAlert {
|
123 |
-
background-color: #
|
124 |
-
color: #
|
125 |
-
border-radius:
|
126 |
border: none;
|
127 |
padding: 1rem 1.5rem;
|
|
|
128 |
}
|
129 |
.stSpinner {
|
130 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
}
|
132 |
</style>
|
133 |
""", unsafe_allow_html=True)
|
134 |
|
135 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
136 |
-
st.title("
|
137 |
-
st.markdown('<p class="subtitle">Powered by Google Gemini -
|
138 |
|
139 |
-
prompt = st.text_area("
|
140 |
|
141 |
-
if st.button("Generate
|
142 |
if prompt.strip() == "":
|
143 |
-
st.error("Please enter a valid prompt
|
144 |
else:
|
145 |
-
with st.spinner("
|
146 |
completed_text = generate_response(prompt)
|
147 |
if "An error occurred" in completed_text:
|
148 |
st.error(completed_text)
|
149 |
else:
|
150 |
-
st.success("
|
151 |
|
152 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
153 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
@@ -157,7 +164,7 @@ if st.button("Generate Elite Solution"):
|
|
157 |
|
158 |
st.markdown("""
|
159 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
160 |
-
|
161 |
</div>
|
162 |
""", unsafe_allow_html=True)
|
163 |
|
|
|
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 |
|
|
|
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>
|
34 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
35 |
|
36 |
body {
|
37 |
+
font-family: 'Poppins', sans-serif;
|
38 |
+
background-color: #f0f7ff;
|
39 |
+
color: #333;
|
40 |
}
|
41 |
.stApp {
|
42 |
max-width: 1200px;
|
|
|
45 |
}
|
46 |
.main-container {
|
47 |
background: #ffffff;
|
48 |
+
border-radius: 20px;
|
49 |
+
padding: 3rem;
|
50 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
51 |
}
|
52 |
h1 {
|
53 |
font-size: 3rem;
|
54 |
font-weight: 700;
|
55 |
+
color: #1e3a8a;
|
56 |
text-align: center;
|
57 |
margin-bottom: 1rem;
|
58 |
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
|
|
60 |
.subtitle {
|
61 |
font-size: 1.2rem;
|
62 |
text-align: center;
|
63 |
+
color: #64748b;
|
64 |
+
margin-bottom: 3rem;
|
65 |
}
|
66 |
.stTextArea textarea {
|
67 |
+
border: 2px solid #cbd5e1;
|
68 |
+
border-radius: 12px;
|
69 |
+
font-size: 1rem;
|
70 |
padding: 1rem;
|
71 |
transition: all 0.3s ease;
|
72 |
+
box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
|
73 |
}
|
74 |
.stTextArea textarea:focus {
|
75 |
+
border-color: #3b82f6;
|
76 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5);
|
77 |
}
|
78 |
.stButton button {
|
79 |
+
background-color: #3b82f6;
|
80 |
color: white;
|
81 |
border: none;
|
82 |
+
border-radius: 12px;
|
83 |
+
font-size: 1.1rem;
|
84 |
font-weight: 600;
|
85 |
+
padding: 0.75rem 2rem;
|
86 |
transition: all 0.3s ease;
|
87 |
width: 100%;
|
88 |
+
box-shadow: 0 4px 6px rgba(59, 130, 246, 0.3);
|
89 |
}
|
90 |
.stButton button:hover {
|
91 |
+
background-color: #2563eb;
|
92 |
transform: translateY(-2px);
|
93 |
+
box-shadow: 0 6px 8px rgba(59, 130, 246, 0.4);
|
94 |
}
|
95 |
.output-container {
|
96 |
+
background: #f8fafc;
|
97 |
+
border-radius: 12px;
|
98 |
padding: 1.5rem;
|
99 |
margin-top: 2rem;
|
100 |
+
border: 1px solid #e2e8f0;
|
101 |
}
|
102 |
.code-block {
|
103 |
+
background-color: #1e293b;
|
104 |
color: #e2e8f0;
|
105 |
font-family: 'Fira Code', monospace;
|
106 |
+
font-size: 0.95rem;
|
107 |
+
border-radius: 12px;
|
108 |
padding: 1.5rem;
|
109 |
margin-top: 1rem;
|
110 |
overflow-x: auto;
|
111 |
}
|
112 |
.stAlert {
|
113 |
+
background-color: #dbeafe;
|
114 |
+
color: #1e40af;
|
115 |
+
border-radius: 12px;
|
116 |
border: none;
|
117 |
padding: 1rem 1.5rem;
|
118 |
+
margin-bottom: 1rem;
|
119 |
}
|
120 |
.stSpinner {
|
121 |
+
color: #3b82f6;
|
122 |
+
}
|
123 |
+
/* Custom scrollbar */
|
124 |
+
::-webkit-scrollbar {
|
125 |
+
width: 8px;
|
126 |
+
height: 8px;
|
127 |
+
}
|
128 |
+
::-webkit-scrollbar-track {
|
129 |
+
background: #f1f5f9;
|
130 |
+
border-radius: 4px;
|
131 |
+
}
|
132 |
+
::-webkit-scrollbar-thumb {
|
133 |
+
background: #94a3b8;
|
134 |
+
border-radius: 4px;
|
135 |
+
}
|
136 |
+
::-webkit-scrollbar-thumb:hover {
|
137 |
+
background: #64748b;
|
138 |
}
|
139 |
</style>
|
140 |
""", unsafe_allow_html=True)
|
141 |
|
142 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
143 |
+
st.title("💻 Advanced AI Code Assistant")
|
144 |
+
st.markdown('<p class="subtitle">Powered by Google Gemini - Expert-level coding solutions</p>', unsafe_allow_html=True)
|
145 |
|
146 |
+
prompt = st.text_area("What advanced coding challenge can I assist you with today?", height=120)
|
147 |
|
148 |
+
if st.button("Generate Expert Code"):
|
149 |
if prompt.strip() == "":
|
150 |
+
st.error("Please enter a valid prompt.")
|
151 |
else:
|
152 |
+
with st.spinner("Generating advanced code solution..."):
|
153 |
completed_text = generate_response(prompt)
|
154 |
if "An error occurred" in completed_text:
|
155 |
st.error(completed_text)
|
156 |
else:
|
157 |
+
st.success("Expert-level code generated successfully!")
|
158 |
|
159 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
160 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
|
|
164 |
|
165 |
st.markdown("""
|
166 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
167 |
+
Crafted with ❤️ by Your Advanced AI Code Assistant
|
168 |
</div>
|
169 |
""", unsafe_allow_html=True)
|
170 |
|