Artificial-superintelligence commited on
Commit
4319a04
Β·
verified Β·
1 Parent(s): ec018dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -70
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="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 {
126
- width: 8px;
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
 
 
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