Update app.py
Browse files
app.py
CHANGED
@@ -27,165 +27,179 @@ 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: 2rem;
|
50 |
-
box-shadow: 0
|
51 |
}
|
52 |
h1 {
|
53 |
font-size: 2.5rem;
|
54 |
-
font-weight:
|
55 |
-
color: #
|
56 |
text-align: center;
|
57 |
-
margin-bottom:
|
58 |
-
text-shadow: 0 0 10px rgba(97, 218, 251, 0.5);
|
59 |
}
|
60 |
.subtitle {
|
61 |
-
font-size:
|
62 |
text-align: center;
|
63 |
-
color: #
|
64 |
margin-bottom: 2rem;
|
65 |
}
|
66 |
.stTextArea textarea {
|
67 |
-
background-color: #
|
68 |
-
color: #
|
69 |
-
border: 1px solid #
|
70 |
-
border-radius:
|
71 |
font-size: 1rem;
|
72 |
-
font-family: '
|
73 |
-
padding:
|
74 |
-
transition: all 0.
|
75 |
}
|
76 |
.stTextArea textarea:focus {
|
77 |
-
border-color: #
|
78 |
-
box-shadow: 0 0 0 2px rgba(
|
79 |
}
|
80 |
.stButton button {
|
81 |
-
background-color: #
|
82 |
-
color: #
|
83 |
border: none;
|
84 |
-
border-radius:
|
85 |
font-size: 1rem;
|
86 |
font-weight: 500;
|
87 |
-
padding: 0.
|
88 |
-
transition: all 0.
|
89 |
-
width: 100%;
|
90 |
}
|
91 |
.stButton button:hover {
|
92 |
-
background-color: #
|
93 |
-
transform: translateY(-
|
94 |
-
box-shadow: 0 4px 8px rgba(97, 218, 251, 0.4);
|
95 |
}
|
96 |
.output-container {
|
97 |
-
background: #
|
98 |
-
border-radius:
|
99 |
padding: 1.5rem;
|
100 |
margin-top: 2rem;
|
101 |
-
border: 1px solid #
|
102 |
}
|
103 |
.code-block {
|
104 |
-
background-color: #
|
105 |
-
color: #
|
106 |
-
font-family: '
|
107 |
font-size: 0.9rem;
|
108 |
-
border-radius:
|
109 |
-
padding: 1.
|
110 |
margin-top: 1rem;
|
111 |
overflow-x: auto;
|
112 |
}
|
113 |
.stAlert {
|
114 |
-
background-color: #
|
115 |
-
color: #
|
116 |
-
border-radius:
|
117 |
-
border:
|
118 |
-
padding: 1rem
|
119 |
margin-bottom: 1rem;
|
120 |
}
|
121 |
.stSpinner {
|
122 |
-
color: #
|
123 |
}
|
124 |
/* Custom scrollbar */
|
125 |
::-webkit-scrollbar {
|
126 |
-
width:
|
127 |
-
height:
|
128 |
}
|
129 |
::-webkit-scrollbar-track {
|
130 |
-
background: #
|
131 |
-
border-radius:
|
132 |
}
|
133 |
::-webkit-scrollbar-thumb {
|
134 |
-
background: #
|
135 |
-
border-radius:
|
136 |
}
|
137 |
::-webkit-scrollbar-thumb:hover {
|
138 |
-
background: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
</style>
|
141 |
""", unsafe_allow_html=True)
|
142 |
|
143 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
144 |
-
st.title("
|
145 |
-
st.markdown('<p class="subtitle">
|
146 |
|
147 |
-
# Add language selection
|
148 |
languages = ["Python", "JavaScript", "Java", "C++", "Ruby", "Go", "Rust", "TypeScript", "PHP", "Swift"]
|
149 |
-
selected_language = st.selectbox("Select your
|
150 |
|
151 |
-
prompt = st.text_area(f"What {selected_language} challenge can I
|
152 |
|
153 |
-
col1, col2 = st.columns([
|
154 |
with col1:
|
155 |
-
generate_button = st.button("Generate
|
156 |
with col2:
|
157 |
-
complexity = st.
|
|
|
|
|
158 |
|
159 |
if generate_button:
|
160 |
if prompt.strip() == "":
|
161 |
-
st.
|
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"
|
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 |
-
|
175 |
-
|
176 |
# Add copy to clipboard button
|
177 |
st.markdown(
|
178 |
f"""
|
179 |
-
<button onclick="navigator.clipboard.writeText(`{completed_text}`)"
|
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: #
|
188 |
-
|
189 |
</div>
|
190 |
""", unsafe_allow_html=True)
|
191 |
|
|
|
27 |
return f"An error occurred: {e}"
|
28 |
|
29 |
# Streamlit UI setup
|
30 |
+
st.set_page_config(page_title="CodeGenius", page_icon="π", layout="wide")
|
31 |
|
32 |
st.markdown("""
|
33 |
<style>
|
34 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&family=JetBrains+Mono:wght@400;500&display=swap');
|
35 |
|
36 |
body {
|
37 |
+
font-family: 'Inter', sans-serif;
|
38 |
+
background-color: #f8f9fa;
|
39 |
+
color: #343a40;
|
40 |
}
|
41 |
.stApp {
|
42 |
+
max-width: 900px;
|
43 |
margin: 0 auto;
|
44 |
padding: 2rem;
|
45 |
}
|
46 |
.main-container {
|
47 |
+
background: #ffffff;
|
48 |
+
border-radius: 12px;
|
49 |
padding: 2rem;
|
50 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
51 |
}
|
52 |
h1 {
|
53 |
font-size: 2.5rem;
|
54 |
+
font-weight: 600;
|
55 |
+
color: #212529;
|
56 |
text-align: center;
|
57 |
+
margin-bottom: 0.5rem;
|
|
|
58 |
}
|
59 |
.subtitle {
|
60 |
+
font-size: 1rem;
|
61 |
text-align: center;
|
62 |
+
color: #6c757d;
|
63 |
margin-bottom: 2rem;
|
64 |
}
|
65 |
.stTextArea textarea {
|
66 |
+
background-color: #f1f3f5;
|
67 |
+
color: #495057;
|
68 |
+
border: 1px solid #ced4da;
|
69 |
+
border-radius: 6px;
|
70 |
font-size: 1rem;
|
71 |
+
font-family: 'JetBrains Mono', monospace;
|
72 |
+
padding: 0.75rem;
|
73 |
+
transition: all 0.2s ease;
|
74 |
}
|
75 |
.stTextArea textarea:focus {
|
76 |
+
border-color: #4dabf7;
|
77 |
+
box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.2);
|
78 |
}
|
79 |
.stButton button {
|
80 |
+
background-color: #4dabf7;
|
81 |
+
color: #ffffff;
|
82 |
border: none;
|
83 |
+
border-radius: 6px;
|
84 |
font-size: 1rem;
|
85 |
font-weight: 500;
|
86 |
+
padding: 0.6rem 1.2rem;
|
87 |
+
transition: all 0.2s ease;
|
|
|
88 |
}
|
89 |
.stButton button:hover {
|
90 |
+
background-color: #3793dd;
|
91 |
+
transform: translateY(-1px);
|
|
|
92 |
}
|
93 |
.output-container {
|
94 |
+
background: #f8f9fa;
|
95 |
+
border-radius: 6px;
|
96 |
padding: 1.5rem;
|
97 |
margin-top: 2rem;
|
98 |
+
border: 1px solid #e9ecef;
|
99 |
}
|
100 |
.code-block {
|
101 |
+
background-color: #f1f3f5;
|
102 |
+
color: #212529;
|
103 |
+
font-family: 'JetBrains Mono', monospace;
|
104 |
font-size: 0.9rem;
|
105 |
+
border-radius: 6px;
|
106 |
+
padding: 1.25rem;
|
107 |
margin-top: 1rem;
|
108 |
overflow-x: auto;
|
109 |
}
|
110 |
.stAlert {
|
111 |
+
background-color: #e9ecef;
|
112 |
+
color: #495057;
|
113 |
+
border-radius: 6px;
|
114 |
+
border: 1px solid #ced4da;
|
115 |
+
padding: 0.75rem 1rem;
|
116 |
margin-bottom: 1rem;
|
117 |
}
|
118 |
.stSpinner {
|
119 |
+
color: #4dabf7;
|
120 |
}
|
121 |
/* Custom scrollbar */
|
122 |
::-webkit-scrollbar {
|
123 |
+
width: 6px;
|
124 |
+
height: 6px;
|
125 |
}
|
126 |
::-webkit-scrollbar-track {
|
127 |
+
background: #f1f3f5;
|
128 |
+
border-radius: 3px;
|
129 |
}
|
130 |
::-webkit-scrollbar-thumb {
|
131 |
+
background: #adb5bd;
|
132 |
+
border-radius: 3px;
|
133 |
}
|
134 |
::-webkit-scrollbar-thumb:hover {
|
135 |
+
background: #868e96;
|
136 |
+
}
|
137 |
+
.language-selector {
|
138 |
+
margin-bottom: 1rem;
|
139 |
+
}
|
140 |
+
.copy-button {
|
141 |
+
background-color: #e9ecef;
|
142 |
+
color: #495057;
|
143 |
+
border: none;
|
144 |
+
border-radius: 4px;
|
145 |
+
padding: 0.4rem 0.8rem;
|
146 |
+
font-size: 0.9rem;
|
147 |
+
cursor: pointer;
|
148 |
+
transition: all 0.2s ease;
|
149 |
+
}
|
150 |
+
.copy-button:hover {
|
151 |
+
background-color: #ced4da;
|
152 |
}
|
153 |
</style>
|
154 |
""", unsafe_allow_html=True)
|
155 |
|
156 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
157 |
+
st.title("π CodeGenius")
|
158 |
+
st.markdown('<p class="subtitle">Elevate Your Code with AI-Powered Insights</p>', unsafe_allow_html=True)
|
159 |
|
|
|
160 |
languages = ["Python", "JavaScript", "Java", "C++", "Ruby", "Go", "Rust", "TypeScript", "PHP", "Swift"]
|
161 |
+
selected_language = st.selectbox("Select your programming language:", languages, key="language-selector")
|
162 |
|
163 |
+
prompt = st.text_area(f"What {selected_language} challenge can I help you with?", height=100)
|
164 |
|
165 |
+
col1, col2, col3 = st.columns([2, 1, 1])
|
166 |
with col1:
|
167 |
+
generate_button = st.button("Generate Solution")
|
168 |
with col2:
|
169 |
+
complexity = st.radio("Complexity", ["Low", "Medium", "High"], horizontal=True)
|
170 |
+
with col3:
|
171 |
+
style = st.radio("Style", ["Concise", "Detailed"], horizontal=True)
|
172 |
|
173 |
if generate_button:
|
174 |
if prompt.strip() == "":
|
175 |
+
st.warning("Please enter a valid prompt.")
|
176 |
else:
|
177 |
with st.spinner(f"Crafting {complexity.lower()} complexity {selected_language} solution..."):
|
178 |
+
completed_text = generate_response(f"{complexity} complexity, {style} {selected_language} code for: {prompt}")
|
179 |
if "An error occurred" in completed_text:
|
180 |
st.error(completed_text)
|
181 |
else:
|
182 |
+
st.success(f"Solution generated successfully!")
|
183 |
|
184 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
185 |
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
186 |
st.code(completed_text, language=selected_language.lower())
|
187 |
st.markdown('</div>', unsafe_allow_html=True)
|
188 |
+
|
|
|
189 |
# Add copy to clipboard button
|
190 |
st.markdown(
|
191 |
f"""
|
192 |
+
<button onclick="navigator.clipboard.writeText(`{completed_text}`)" class="copy-button">
|
193 |
Copy to Clipboard
|
194 |
</button>
|
195 |
""",
|
196 |
unsafe_allow_html=True
|
197 |
)
|
198 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
199 |
|
200 |
st.markdown("""
|
201 |
+
<div style='text-align: center; margin-top: 2rem; color: #adb5bd; font-size: 0.9rem;'>
|
202 |
+
Powered by CodeGenius AI β’ Simplifying Complex Code Challenges
|
203 |
</div>
|
204 |
""", unsafe_allow_html=True)
|
205 |
|