Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ generation_config = {
|
|
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,98 +27,99 @@ 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>
|
34 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
35 |
|
36 |
body {
|
37 |
-
font-family: '
|
38 |
-
background-color: #
|
39 |
-
color: #
|
40 |
}
|
41 |
.stApp {
|
42 |
-
max-width:
|
43 |
margin: 0 auto;
|
44 |
padding: 2rem;
|
45 |
}
|
46 |
.main-container {
|
47 |
-
background: #
|
48 |
-
border-radius:
|
49 |
-
padding:
|
50 |
-
box-shadow: 0
|
51 |
}
|
52 |
h1 {
|
53 |
-
font-size:
|
54 |
font-weight: 700;
|
55 |
-
color: #
|
56 |
text-align: center;
|
57 |
margin-bottom: 1rem;
|
58 |
-
text-shadow:
|
59 |
}
|
60 |
.subtitle {
|
61 |
-
font-size: 1.
|
62 |
text-align: center;
|
63 |
-
color: #
|
64 |
-
margin-bottom:
|
65 |
}
|
66 |
.stTextArea textarea {
|
67 |
-
|
68 |
-
|
|
|
|
|
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: #
|
76 |
-
box-shadow: 0 0 0
|
77 |
}
|
78 |
.stButton button {
|
79 |
-
background-color: #
|
80 |
-
color:
|
81 |
border: none;
|
82 |
-
border-radius:
|
83 |
-
font-size:
|
84 |
-
font-weight:
|
85 |
-
padding: 0.75rem
|
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: #
|
92 |
transform: translateY(-2px);
|
93 |
-
box-shadow: 0
|
94 |
}
|
95 |
.output-container {
|
96 |
-
background: #
|
97 |
-
border-radius:
|
98 |
padding: 1.5rem;
|
99 |
margin-top: 2rem;
|
100 |
-
border: 1px solid #
|
101 |
}
|
102 |
.code-block {
|
103 |
-
background-color: #
|
104 |
-
color: #
|
105 |
font-family: 'Fira Code', monospace;
|
106 |
-
font-size: 0.
|
107 |
-
border-radius:
|
108 |
padding: 1.5rem;
|
109 |
margin-top: 1rem;
|
110 |
overflow-x: auto;
|
111 |
}
|
112 |
.stAlert {
|
113 |
-
background-color: #
|
114 |
-
color: #
|
115 |
-
border-radius:
|
116 |
border: none;
|
117 |
padding: 1rem 1.5rem;
|
118 |
margin-bottom: 1rem;
|
119 |
}
|
120 |
.stSpinner {
|
121 |
-
color: #
|
122 |
}
|
123 |
/* Custom scrollbar */
|
124 |
::-webkit-scrollbar {
|
@@ -126,45 +127,65 @@ st.markdown("""
|
|
126 |
height: 8px;
|
127 |
}
|
128 |
::-webkit-scrollbar-track {
|
129 |
-
background: #
|
130 |
border-radius: 4px;
|
131 |
}
|
132 |
::-webkit-scrollbar-thumb {
|
133 |
-
background: #
|
134 |
border-radius: 4px;
|
135 |
}
|
136 |
::-webkit-scrollbar-thumb:hover {
|
137 |
-
background: #
|
138 |
}
|
139 |
</style>
|
140 |
""", unsafe_allow_html=True)
|
141 |
|
142 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
143 |
-
st.title("
|
144 |
-
st.markdown('<p class="subtitle">
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
prompt = st.text_area("What
|
147 |
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
if prompt.strip() == "":
|
150 |
st.error("Please enter a valid prompt.")
|
151 |
else:
|
152 |
-
with st.spinner("
|
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)
|
161 |
-
st.code(completed_text)
|
162 |
st.markdown('</div>', unsafe_allow_html=True)
|
163 |
st.markdown('</div>', unsafe_allow_html=True)
|
164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
st.markdown("""
|
166 |
-
<div style='text-align: center; margin-top: 2rem; color: #
|
167 |
-
|
168 |
</div>
|
169 |
""", unsafe_allow_html=True)
|
170 |
|
|
|
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="CodeCraft AI", page_icon="🧠", layout="wide")
|
31 |
|
32 |
st.markdown("""
|
33 |
<style>
|
34 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&family=Fira+Code:wght@400;500&display=swap');
|
35 |
|
36 |
body {
|
37 |
+
font-family: 'Roboto', sans-serif;
|
38 |
+
background-color: #1e1e1e;
|
39 |
+
color: #e0e0e0;
|
40 |
}
|
41 |
.stApp {
|
42 |
+
max-width: 1000px;
|
43 |
margin: 0 auto;
|
44 |
padding: 2rem;
|
45 |
}
|
46 |
.main-container {
|
47 |
+
background: #2d2d2d;
|
48 |
+
border-radius: 15px;
|
49 |
+
padding: 2rem;
|
50 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
51 |
}
|
52 |
h1 {
|
53 |
+
font-size: 2.5rem;
|
54 |
font-weight: 700;
|
55 |
+
color: #61dafb;
|
56 |
text-align: center;
|
57 |
margin-bottom: 1rem;
|
58 |
+
text-shadow: 0 0 10px rgba(97, 218, 251, 0.5);
|
59 |
}
|
60 |
.subtitle {
|
61 |
+
font-size: 1.1rem;
|
62 |
text-align: center;
|
63 |
+
color: #bbb;
|
64 |
+
margin-bottom: 2rem;
|
65 |
}
|
66 |
.stTextArea textarea {
|
67 |
+
background-color: #3a3a3a;
|
68 |
+
color: #e0e0e0;
|
69 |
+
border: 1px solid #4a4a4a;
|
70 |
+
border-radius: 8px;
|
71 |
font-size: 1rem;
|
72 |
+
font-family: 'Fira Code', monospace;
|
73 |
padding: 1rem;
|
74 |
transition: all 0.3s ease;
|
|
|
75 |
}
|
76 |
.stTextArea textarea:focus {
|
77 |
+
border-color: #61dafb;
|
78 |
+
box-shadow: 0 0 0 2px rgba(97, 218, 251, 0.3);
|
79 |
}
|
80 |
.stButton button {
|
81 |
+
background-color: #61dafb;
|
82 |
+
color: #1e1e1e;
|
83 |
border: none;
|
84 |
+
border-radius: 8px;
|
85 |
+
font-size: 1rem;
|
86 |
+
font-weight: 500;
|
87 |
+
padding: 0.75rem 1.5rem;
|
88 |
transition: all 0.3s ease;
|
89 |
width: 100%;
|
|
|
90 |
}
|
91 |
.stButton button:hover {
|
92 |
+
background-color: #4fa8d5;
|
93 |
transform: translateY(-2px);
|
94 |
+
box-shadow: 0 4px 8px rgba(97, 218, 251, 0.4);
|
95 |
}
|
96 |
.output-container {
|
97 |
+
background: #3a3a3a;
|
98 |
+
border-radius: 8px;
|
99 |
padding: 1.5rem;
|
100 |
margin-top: 2rem;
|
101 |
+
border: 1px solid #4a4a4a;
|
102 |
}
|
103 |
.code-block {
|
104 |
+
background-color: #2b2b2b;
|
105 |
+
color: #e0e0e0;
|
106 |
font-family: 'Fira Code', monospace;
|
107 |
+
font-size: 0.9rem;
|
108 |
+
border-radius: 8px;
|
109 |
padding: 1.5rem;
|
110 |
margin-top: 1rem;
|
111 |
overflow-x: auto;
|
112 |
}
|
113 |
.stAlert {
|
114 |
+
background-color: #4a4a4a;
|
115 |
+
color: #e0e0e0;
|
116 |
+
border-radius: 8px;
|
117 |
border: none;
|
118 |
padding: 1rem 1.5rem;
|
119 |
margin-bottom: 1rem;
|
120 |
}
|
121 |
.stSpinner {
|
122 |
+
color: #61dafb;
|
123 |
}
|
124 |
/* Custom scrollbar */
|
125 |
::-webkit-scrollbar {
|
|
|
127 |
height: 8px;
|
128 |
}
|
129 |
::-webkit-scrollbar-track {
|
130 |
+
background: #2d2d2d;
|
131 |
border-radius: 4px;
|
132 |
}
|
133 |
::-webkit-scrollbar-thumb {
|
134 |
+
background: #4a4a4a;
|
135 |
border-radius: 4px;
|
136 |
}
|
137 |
::-webkit-scrollbar-thumb:hover {
|
138 |
+
background: #5a5a5a;
|
139 |
}
|
140 |
</style>
|
141 |
""", unsafe_allow_html=True)
|
142 |
|
143 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
144 |
+
st.title("🧠 CodeCraft AI")
|
145 |
+
st.markdown('<p class="subtitle">Empowering Developers with Advanced AI-Driven Solutions</p>', unsafe_allow_html=True)
|
146 |
+
|
147 |
+
# Add language selection
|
148 |
+
languages = ["Python", "JavaScript", "Java", "C++", "Ruby", "Go", "Rust", "TypeScript", "PHP", "Swift"]
|
149 |
+
selected_language = st.selectbox("Select your preferred programming language:", languages)
|
150 |
|
151 |
+
prompt = st.text_area(f"What {selected_language} challenge can I assist you with today?", height=120)
|
152 |
|
153 |
+
col1, col2 = st.columns([3, 1])
|
154 |
+
with col1:
|
155 |
+
generate_button = st.button("Generate Expert Code")
|
156 |
+
with col2:
|
157 |
+
complexity = st.select_slider("Code Complexity", options=["Low", "Medium", "High"])
|
158 |
+
|
159 |
+
if generate_button:
|
160 |
if prompt.strip() == "":
|
161 |
st.error("Please enter a valid prompt.")
|
162 |
else:
|
163 |
+
with st.spinner(f"Crafting {complexity.lower()} complexity {selected_language} solution..."):
|
164 |
+
completed_text = generate_response(f"{complexity} complexity {selected_language} code for: {prompt}")
|
165 |
if "An error occurred" in completed_text:
|
166 |
st.error(completed_text)
|
167 |
else:
|
168 |
+
st.success(f"Expert-level {selected_language} code generated successfully!")
|
169 |
|
170 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
171 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
172 |
+
st.code(completed_text, language=selected_language.lower())
|
173 |
st.markdown('</div>', unsafe_allow_html=True)
|
174 |
st.markdown('</div>', unsafe_allow_html=True)
|
175 |
|
176 |
+
# Add copy to clipboard button
|
177 |
+
st.markdown(
|
178 |
+
f"""
|
179 |
+
<button onclick="navigator.clipboard.writeText(`{completed_text}`)" style="margin-top: 10px; background-color: #4a4a4a; color: #e0e0e0; border: none; padding: 5px 10px; border-radius: 5px; cursor: pointer;">
|
180 |
+
Copy to Clipboard
|
181 |
+
</button>
|
182 |
+
""",
|
183 |
+
unsafe_allow_html=True
|
184 |
+
)
|
185 |
+
|
186 |
st.markdown("""
|
187 |
+
<div style='text-align: center; margin-top: 2rem; color: #bbb;'>
|
188 |
+
Engineered with 💡 by CodeCraft AI - Elevating Your Coding Experience
|
189 |
</div>
|
190 |
""", unsafe_allow_html=True)
|
191 |
|