Spaces:
Running
Running
update to gradio
Browse files- app.css +578 -43
- app.py +191 -147
- requirements.txt +0 -1
app.css
CHANGED
@@ -1,79 +1,614 @@
|
|
1 |
-
/*
|
2 |
|
3 |
:root {
|
4 |
-
--
|
5 |
-
--
|
6 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
}
|
8 |
|
9 |
-
@media (prefers-color-scheme:
|
10 |
:root {
|
11 |
-
--text-color: #
|
12 |
-
--bg-color: #
|
13 |
-
--
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
}
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
22 |
-
.
|
23 |
-
margin
|
24 |
-
color:
|
|
|
|
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
}
|
32 |
|
33 |
-
|
|
|
34 |
background: var(--bg-color);
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
display: flex;
|
|
|
42 |
gap: 8px;
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
-
.
|
47 |
-
|
48 |
-
height: 12px;
|
49 |
-
border-radius: 50%;
|
50 |
-
background: #ff5f56;
|
51 |
}
|
52 |
|
53 |
-
.
|
54 |
-
|
55 |
}
|
56 |
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
display: flex;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
align-items: center;
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
}
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
.html_content {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
width: 100%;
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
}
|
|
|
1 |
+
/* Modern coding editor styling for AnyCoder */
|
2 |
|
3 |
:root {
|
4 |
+
--primary-color: #007acc;
|
5 |
+
--secondary-color: #1e1e1e;
|
6 |
+
--accent-color: #4ec9b0;
|
7 |
+
--text-color: #d4d4d4;
|
8 |
+
--bg-color: #252526;
|
9 |
+
--surface-color: #2d2d30;
|
10 |
+
--border-color: #3e3e42;
|
11 |
+
--success-color: #4ec9b0;
|
12 |
+
--error-color: #f44747;
|
13 |
+
--warning-color: #ce9178;
|
14 |
+
--html-bg: #ffffff;
|
15 |
+
--code-bg: #1e1e1e;
|
16 |
+
--sidebar-bg: #252526;
|
17 |
}
|
18 |
|
19 |
+
@media (prefers-color-scheme: light) {
|
20 |
:root {
|
21 |
+
--text-color: #333333;
|
22 |
+
--bg-color: #f3f3f3;
|
23 |
+
--surface-color: #ffffff;
|
24 |
+
--border-color: #e1e1e1;
|
25 |
+
--html-bg: #ffffff;
|
26 |
+
--code-bg: #f8f8f8;
|
27 |
+
--sidebar-bg: #f5f5f5;
|
28 |
}
|
29 |
}
|
30 |
|
31 |
+
/* App header */
|
32 |
+
.app-header {
|
33 |
+
display: flex;
|
34 |
+
align-items: center;
|
35 |
+
gap: 12px;
|
36 |
+
padding: 16px 24px;
|
37 |
+
background: var(--surface-color);
|
38 |
+
border-bottom: 1px solid var(--border-color);
|
39 |
+
margin-bottom: 0;
|
40 |
}
|
41 |
|
42 |
+
.app-header h1 {
|
43 |
+
margin: 0;
|
44 |
+
color: var(--text-color);
|
45 |
+
font-size: 24px;
|
46 |
+
font-weight: 600;
|
47 |
}
|
48 |
|
49 |
+
.app-header .subtitle {
|
50 |
+
color: var(--text-color);
|
51 |
+
opacity: 0.7;
|
52 |
+
font-size: 14px;
|
53 |
+
margin-left: auto;
|
54 |
}
|
55 |
|
56 |
+
/* Main layout */
|
57 |
+
.gradio-container {
|
58 |
background: var(--bg-color);
|
59 |
+
min-height: 100vh;
|
60 |
+
}
|
61 |
+
|
62 |
+
/* Left sidebar */
|
63 |
+
.code-input {
|
64 |
+
background: var(--surface-color) !important;
|
65 |
+
border: 1px solid var(--border-color) !important;
|
66 |
+
border-radius: 8px !important;
|
67 |
+
color: var(--text-color) !important;
|
68 |
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
|
69 |
+
font-size: 14px !important;
|
70 |
+
}
|
71 |
+
|
72 |
+
.code-input:focus {
|
73 |
+
border-color: var(--primary-color) !important;
|
74 |
+
box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.2) !important;
|
75 |
+
}
|
76 |
+
|
77 |
+
.model-display {
|
78 |
+
color: var(--text-color) !important;
|
79 |
+
font-size: 14px !important;
|
80 |
+
margin: 0 !important;
|
81 |
+
}
|
82 |
+
|
83 |
+
.icon-btn {
|
84 |
+
background: var(--surface-color) !important;
|
85 |
+
border: 1px solid var(--border-color) !important;
|
86 |
+
color: var(--text-color) !important;
|
87 |
+
border-radius: 6px !important;
|
88 |
+
padding: 8px 12px !important;
|
89 |
+
transition: all 0.2s ease !important;
|
90 |
+
}
|
91 |
+
|
92 |
+
.icon-btn:hover {
|
93 |
+
background: var(--primary-color) !important;
|
94 |
+
color: white !important;
|
95 |
+
transform: translateY(-1px) !important;
|
96 |
+
}
|
97 |
+
|
98 |
+
.generate-btn {
|
99 |
+
background: var(--primary-color) !important;
|
100 |
+
color: white !important;
|
101 |
+
border: none !important;
|
102 |
+
border-radius: 8px !important;
|
103 |
+
font-weight: 600 !important;
|
104 |
+
transition: all 0.2s ease !important;
|
105 |
+
}
|
106 |
+
|
107 |
+
.generate-btn:hover {
|
108 |
+
background: #005a9e !important;
|
109 |
+
transform: translateY(-1px) !important;
|
110 |
+
box-shadow: 0 4px 12px rgba(0, 122, 204, 0.3) !important;
|
111 |
+
}
|
112 |
+
|
113 |
+
.clear-btn {
|
114 |
+
background: var(--surface-color) !important;
|
115 |
+
border: 1px solid var(--border-color) !important;
|
116 |
+
color: var(--text-color) !important;
|
117 |
+
border-radius: 6px !important;
|
118 |
+
}
|
119 |
+
|
120 |
+
.quick-example-btn {
|
121 |
+
background: var(--surface-color) !important;
|
122 |
+
border: 1px solid var(--border-color) !important;
|
123 |
+
color: var(--text-color) !important;
|
124 |
+
border-radius: 6px !important;
|
125 |
+
font-size: 12px !important;
|
126 |
+
padding: 8px 12px !important;
|
127 |
+
transition: all 0.2s ease !important;
|
128 |
+
}
|
129 |
+
|
130 |
+
.quick-example-btn:hover {
|
131 |
+
background: var(--primary-color) !important;
|
132 |
+
color: white !important;
|
133 |
+
border-color: var(--primary-color) !important;
|
134 |
+
}
|
135 |
+
|
136 |
+
/* Code editor tabs */
|
137 |
+
.code-tabs {
|
138 |
+
background: var(--code-bg) !important;
|
139 |
+
border: 1px solid var(--border-color) !important;
|
140 |
+
border-radius: 8px !important;
|
141 |
+
overflow: hidden !important;
|
142 |
+
}
|
143 |
+
|
144 |
+
.code-tab, .preview-tab {
|
145 |
+
background: var(--code-bg) !important;
|
146 |
+
color: var(--text-color) !important;
|
147 |
+
border: none !important;
|
148 |
+
padding: 12px 20px !important;
|
149 |
+
font-weight: 500 !important;
|
150 |
+
}
|
151 |
+
|
152 |
+
.code-tab[aria-selected="true"], .preview-tab[aria-selected="true"] {
|
153 |
+
background: var(--surface-color) !important;
|
154 |
+
color: var(--primary-color) !important;
|
155 |
+
border-bottom: 2px solid var(--primary-color) !important;
|
156 |
+
}
|
157 |
+
|
158 |
+
/* Code editor */
|
159 |
+
.code-editor {
|
160 |
+
background: var(--code-bg) !important;
|
161 |
+
border: none !important;
|
162 |
+
border-radius: 0 !important;
|
163 |
+
color: var(--text-color) !important;
|
164 |
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
|
165 |
+
font-size: 14px !important;
|
166 |
+
line-height: 1.5 !important;
|
167 |
+
min-height: 500px !important;
|
168 |
+
}
|
169 |
+
|
170 |
+
.code-editor .monaco-editor {
|
171 |
+
background: var(--code-bg) !important;
|
172 |
+
}
|
173 |
+
|
174 |
+
/* HTML content */
|
175 |
+
.html_content {
|
176 |
+
width: 100% !important;
|
177 |
+
height: 500px !important;
|
178 |
+
border: none !important;
|
179 |
+
border-radius: 0 !important;
|
180 |
+
background: var(--html-bg) !important;
|
181 |
}
|
182 |
|
183 |
+
/* Status bar */
|
184 |
+
.status-bar {
|
185 |
+
background: var(--surface-color) !important;
|
186 |
+
border-top: 1px solid var(--border-color) !important;
|
187 |
+
padding: 8px 16px !important;
|
188 |
+
font-size: 12px !important;
|
189 |
+
color: var(--text-color) !important;
|
190 |
+
}
|
191 |
+
|
192 |
+
.status-indicator {
|
193 |
display: flex;
|
194 |
+
align-items: center;
|
195 |
gap: 8px;
|
196 |
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
197 |
+
}
|
198 |
+
|
199 |
+
.status-indicator.generating {
|
200 |
+
color: var(--warning-color);
|
201 |
}
|
202 |
|
203 |
+
.status-indicator.success {
|
204 |
+
color: var(--success-color);
|
|
|
|
|
|
|
205 |
}
|
206 |
|
207 |
+
.status-indicator.error {
|
208 |
+
color: var(--error-color);
|
209 |
}
|
210 |
|
211 |
+
/* Modals */
|
212 |
+
.modal {
|
213 |
+
max-width: 420px;
|
214 |
+
padding: 16px 20px 12px 20px !important;
|
215 |
+
border-radius: 10px;
|
216 |
+
background: #23232b;
|
217 |
+
box-shadow: 0 2px 16px rgba(0,0,0,0.12);
|
218 |
+
border: 1px solid #29293a;
|
219 |
+
}
|
220 |
+
|
221 |
+
.modal h3 {
|
222 |
+
font-size: 1.1em;
|
223 |
+
margin-bottom: 8px;
|
224 |
+
margin-top: 0;
|
225 |
+
}
|
226 |
+
|
227 |
+
.modal-input {
|
228 |
+
font-size: 0.95em;
|
229 |
+
padding: 8px 10px;
|
230 |
+
border-radius: 6px;
|
231 |
+
background: #18181f;
|
232 |
+
border: 1px solid #29293a;
|
233 |
+
margin-bottom: 10px;
|
234 |
+
}
|
235 |
+
|
236 |
+
.modal .gr-button {
|
237 |
+
min-width: 80px;
|
238 |
+
height: 32px;
|
239 |
+
font-size: 0.95em;
|
240 |
+
margin-right: 8px;
|
241 |
+
border-radius: 6px;
|
242 |
+
padding: 0 10px;
|
243 |
+
}
|
244 |
+
|
245 |
+
/* Drawers */
|
246 |
+
.drawer {
|
247 |
+
max-width: 420px;
|
248 |
+
padding: 12px 16px 8px 16px !important;
|
249 |
+
border-radius: 10px;
|
250 |
+
background: #23232b;
|
251 |
+
box-shadow: 0 2px 16px rgba(0,0,0,0.12);
|
252 |
+
border: 1px solid #29293a;
|
253 |
+
}
|
254 |
+
|
255 |
+
.drawer h3 {
|
256 |
+
font-size: 1.1em;
|
257 |
+
margin-bottom: 8px;
|
258 |
+
margin-top: 0;
|
259 |
+
}
|
260 |
+
|
261 |
+
/* History chatbot */
|
262 |
+
.history_chatbot {
|
263 |
+
background: #18181f !important;
|
264 |
+
border-radius: 8px !important;
|
265 |
+
padding: 8px !important;
|
266 |
+
font-size: 0.97em !important;
|
267 |
+
min-height: 200px;
|
268 |
+
max-height: 320px;
|
269 |
+
overflow-y: auto;
|
270 |
}
|
271 |
|
272 |
+
.history_chatbot .message {
|
273 |
+
margin-bottom: 6px !important;
|
274 |
+
padding: 6px 10px !important;
|
275 |
+
border-radius: 6px !important;
|
276 |
+
}
|
277 |
+
|
278 |
+
/* Model cards */
|
279 |
+
.model-select-row {
|
280 |
display: flex;
|
281 |
+
gap: 8px;
|
282 |
+
justify-content: flex-start;
|
283 |
+
margin-bottom: 8px;
|
284 |
+
}
|
285 |
+
|
286 |
+
.model-card-btn {
|
287 |
+
min-width: 80px;
|
288 |
+
max-width: 120px;
|
289 |
+
height: 40px;
|
290 |
+
border-radius: 8px;
|
291 |
+
font-size: 1em;
|
292 |
+
font-weight: 600;
|
293 |
+
text-align: center;
|
294 |
+
padding: 0 8px;
|
295 |
+
white-space: nowrap;
|
296 |
+
overflow: hidden;
|
297 |
+
text-overflow: ellipsis;
|
298 |
+
transition: background 0.2s, box-shadow 0.2s;
|
299 |
+
}
|
300 |
+
|
301 |
+
.model-card-btn:hover {
|
302 |
+
background: #2a2a2a;
|
303 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
304 |
+
}
|
305 |
+
|
306 |
+
/* Image input */
|
307 |
+
.image-input {
|
308 |
+
background: var(--surface-color) !important;
|
309 |
+
border: 1px solid var(--border-color) !important;
|
310 |
+
border-radius: 8px !important;
|
311 |
+
}
|
312 |
+
|
313 |
+
/* Responsive design */
|
314 |
+
@media (max-width: 768px) {
|
315 |
+
.app-header {
|
316 |
+
flex-direction: column;
|
317 |
+
gap: 8px;
|
318 |
+
text-align: center;
|
319 |
+
}
|
320 |
+
|
321 |
+
.app-header .subtitle {
|
322 |
+
margin-left: 0;
|
323 |
+
}
|
324 |
+
|
325 |
+
.code-editor {
|
326 |
+
min-height: 300px !important;
|
327 |
+
}
|
328 |
+
|
329 |
+
.html_content {
|
330 |
+
height: 300px !important;
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
/* Loading animation */
|
335 |
+
@keyframes spin {
|
336 |
+
0% { transform: rotate(0deg); }
|
337 |
+
100% { transform: rotate(360deg); }
|
338 |
+
}
|
339 |
+
|
340 |
+
/* Scrollbar styling */
|
341 |
+
::-webkit-scrollbar {
|
342 |
+
width: 8px;
|
343 |
+
}
|
344 |
+
|
345 |
+
::-webkit-scrollbar-track {
|
346 |
+
background: var(--bg-color);
|
347 |
+
}
|
348 |
+
|
349 |
+
::-webkit-scrollbar-thumb {
|
350 |
+
background: var(--border-color);
|
351 |
+
border-radius: 4px;
|
352 |
+
}
|
353 |
+
|
354 |
+
::-webkit-scrollbar-thumb:hover {
|
355 |
+
background: var(--primary-color);
|
356 |
+
}
|
357 |
+
|
358 |
+
/* Sidebar styling */
|
359 |
+
.sidebar {
|
360 |
+
position: relative;
|
361 |
+
overflow: visible;
|
362 |
+
min-width: 320px;
|
363 |
+
max-width: 360px;
|
364 |
+
padding: 18px 12px 12px 12px;
|
365 |
+
background: #20202a;
|
366 |
+
border-right: 1px solid #23232b;
|
367 |
+
display: flex;
|
368 |
+
flex-direction: column;
|
369 |
+
gap: 12px;
|
370 |
+
}
|
371 |
+
.sidebar-header {
|
372 |
+
display: flex;
|
373 |
+
flex-direction: column;
|
374 |
align-items: center;
|
375 |
+
padding: 32px 0 16px 0;
|
376 |
+
background: var(--surface-color);
|
377 |
+
border-bottom: 1px solid var(--border-color);
|
378 |
+
}
|
379 |
+
.sidebar-header h1 {
|
380 |
+
margin: 8px 0 0 0;
|
381 |
+
font-size: 22px;
|
382 |
+
color: var(--primary-color);
|
383 |
+
font-weight: 700;
|
384 |
+
}
|
385 |
+
.sidebar-desc {
|
386 |
+
font-size: 13px;
|
387 |
+
color: var(--text-color);
|
388 |
+
opacity: 0.7;
|
389 |
+
margin-top: 4px;
|
390 |
+
text-align: center;
|
391 |
+
}
|
392 |
+
.sidebar-section {
|
393 |
+
padding: 18px 24px 0 24px;
|
394 |
+
}
|
395 |
+
.sidebar-section h3 {
|
396 |
+
font-size: 15px;
|
397 |
+
color: var(--primary-color);
|
398 |
+
margin-bottom: 8px;
|
399 |
+
}
|
400 |
+
.sidebar-section ul {
|
401 |
+
padding-left: 18px;
|
402 |
+
font-size: 13px;
|
403 |
+
color: var(--text-color);
|
404 |
+
opacity: 0.85;
|
405 |
+
}
|
406 |
+
.sidebar-btn {
|
407 |
+
width: 100%;
|
408 |
+
margin: 6px 0;
|
409 |
+
border-radius: 6px !important;
|
410 |
+
font-size: 14px !important;
|
411 |
+
font-weight: 500 !important;
|
412 |
+
background: var(--surface-color) !important;
|
413 |
+
color: var(--primary-color) !important;
|
414 |
+
border: 1px solid var(--border-color) !important;
|
415 |
+
transition: all 0.2s;
|
416 |
+
}
|
417 |
+
.sidebar-btn:hover {
|
418 |
+
background: var(--primary-color) !important;
|
419 |
+
color: #fff !important;
|
420 |
+
}
|
421 |
+
.quick-example-btn {
|
422 |
+
margin: 4px 0;
|
423 |
+
font-size: 13px !important;
|
424 |
+
background: var(--surface-color) !important;
|
425 |
+
color: var(--text-color) !important;
|
426 |
+
border: 1px solid var(--border-color) !important;
|
427 |
+
border-radius: 6px !important;
|
428 |
+
transition: all 0.2s;
|
429 |
+
}
|
430 |
+
.quick-example-btn:hover {
|
431 |
+
background: var(--primary-color) !important;
|
432 |
+
color: #fff !important;
|
433 |
+
}
|
434 |
+
|
435 |
+
/* Main area styling */
|
436 |
+
.main-area {
|
437 |
+
background: var(--bg-color);
|
438 |
+
min-height: 100vh;
|
439 |
+
padding: 32px 40px 32px 40px;
|
440 |
+
display: flex;
|
441 |
+
flex-direction: column;
|
442 |
+
box-shadow: 0 2px 16px rgba(0,0,0,0.04);
|
443 |
+
}
|
444 |
+
.model-display {
|
445 |
+
color: var(--primary-color) !important;
|
446 |
+
font-size: 15px !important;
|
447 |
+
margin-bottom: 8px !important;
|
448 |
+
}
|
449 |
+
.code-input, .image-input {
|
450 |
+
margin-bottom: 8px !important;
|
451 |
+
}
|
452 |
+
.generate-btn, .clear-btn {
|
453 |
+
min-width: 80px;
|
454 |
+
height: 32px;
|
455 |
+
font-size: 0.97em;
|
456 |
+
border-radius: 6px;
|
457 |
+
margin-right: 6px;
|
458 |
}
|
459 |
|
460 |
+
/* Code editor and preview */
|
461 |
+
.code-tabs {
|
462 |
+
background: var(--code-bg) !important;
|
463 |
+
border: 1px solid var(--border-color) !important;
|
464 |
+
border-radius: 8px !important;
|
465 |
+
margin-top: 24px !important;
|
466 |
+
overflow: hidden !important;
|
467 |
+
}
|
468 |
+
.code-tab, .preview-tab {
|
469 |
+
background: var(--code-bg) !important;
|
470 |
+
color: var(--text-color) !important;
|
471 |
+
border: none !important;
|
472 |
+
padding: 12px 20px !important;
|
473 |
+
font-weight: 500 !important;
|
474 |
+
}
|
475 |
+
.code-tab[aria-selected="true"], .preview-tab[aria-selected="true"] {
|
476 |
+
background: var(--surface-color) !important;
|
477 |
+
color: var(--primary-color) !important;
|
478 |
+
border-bottom: 2px solid var(--primary-color) !important;
|
479 |
+
}
|
480 |
+
.code-editor {
|
481 |
+
background: var(--code-bg) !important;
|
482 |
+
border: none !important;
|
483 |
+
border-radius: 0 !important;
|
484 |
+
color: var(--text-color) !important;
|
485 |
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
|
486 |
+
font-size: 15px !important;
|
487 |
+
line-height: 1.5 !important;
|
488 |
+
min-height: 500px !important;
|
489 |
+
}
|
490 |
+
.code-editor .monaco-editor {
|
491 |
+
background: var(--code-bg) !important;
|
492 |
+
}
|
493 |
.html_content {
|
494 |
+
width: 100% !important;
|
495 |
+
height: 500px !important;
|
496 |
+
border: none !important;
|
497 |
+
border-radius: 0 !important;
|
498 |
+
background: var(--html-bg) !important;
|
499 |
+
}
|
500 |
+
.status-bar {
|
501 |
+
background: var(--surface-color) !important;
|
502 |
+
border-top: 1px solid var(--border-color) !important;
|
503 |
+
padding: 8px 16px !important;
|
504 |
+
font-size: 13px !important;
|
505 |
+
color: var(--text-color) !important;
|
506 |
+
margin-top: 0 !important;
|
507 |
+
}
|
508 |
+
.status-indicator {
|
509 |
+
display: flex;
|
510 |
+
align-items: center;
|
511 |
+
gap: 8px;
|
512 |
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
513 |
+
}
|
514 |
+
.status-indicator.generating {
|
515 |
+
color: var(--warning-color);
|
516 |
+
}
|
517 |
+
.status-indicator.success {
|
518 |
+
color: var(--success-color);
|
519 |
+
}
|
520 |
+
.status-indicator.error {
|
521 |
+
color: var(--error-color);
|
522 |
+
}
|
523 |
+
|
524 |
+
/* Modal and drawer styling remain as before */
|
525 |
+
|
526 |
+
/* Responsive design */
|
527 |
+
@media (max-width: 900px) {
|
528 |
+
.main-area {
|
529 |
+
padding: 16px 4vw 16px 4vw;
|
530 |
+
}
|
531 |
+
.sidebar {
|
532 |
+
min-width: 180px;
|
533 |
+
padding: 0 0 0 0;
|
534 |
+
}
|
535 |
+
}
|
536 |
+
@media (max-width: 600px) {
|
537 |
+
.main-area {
|
538 |
+
padding: 8px 2vw 8px 2vw;
|
539 |
+
}
|
540 |
+
.sidebar {
|
541 |
+
display: none;
|
542 |
+
}
|
543 |
+
.code-editor {
|
544 |
+
min-height: 250px !important;
|
545 |
+
}
|
546 |
+
.html_content {
|
547 |
+
height: 220px !important;
|
548 |
+
}
|
549 |
+
}
|
550 |
+
|
551 |
+
.sidebar .modal,
|
552 |
+
.sidebar .drawer {
|
553 |
+
position: absolute;
|
554 |
+
left: 0;
|
555 |
+
top: 420px;
|
556 |
width: 100%;
|
557 |
+
z-index: 10;
|
558 |
+
background: #23232b;
|
559 |
+
box-shadow: 2px 0 16px rgba(0,0,0,0.18);
|
560 |
+
border-radius: 10px;
|
561 |
+
border: 1px solid #29293a;
|
562 |
+
padding: 18px 16px 12px 16px !important;
|
563 |
+
min-width: 320px;
|
564 |
+
max-width: 360px;
|
565 |
}
|
566 |
|
567 |
+
/* Sidebar section headings and text */
|
568 |
+
.sidebar-section h3,
|
569 |
+
.sidebar-section {
|
570 |
+
color: #4fc3f7 !important;
|
571 |
+
}
|
572 |
+
.sidebar-section ul,
|
573 |
+
.sidebar-section li {
|
574 |
+
color: #e0e0e0 !important;
|
575 |
+
}
|
576 |
+
|
577 |
+
/* Quick Examples heading */
|
578 |
+
.sidebar .sidebar-section h3 {
|
579 |
+
color: #4fc3f7 !important;
|
580 |
+
}
|
581 |
+
|
582 |
+
/* Tab labels */
|
583 |
+
.code-tabs .tab-nav .tab-nav-btn,
|
584 |
+
.code-tabs .tab-nav .tab-nav-btn.selected {
|
585 |
+
color: #f5f5f5 !important;
|
586 |
+
font-weight: 600;
|
587 |
+
}
|
588 |
+
.code-tabs .tab-nav .tab-nav-btn.selected {
|
589 |
+
border-bottom: 2px solid #ff9800 !important;
|
590 |
+
}
|
591 |
+
|
592 |
+
/* Live Preview tab content */
|
593 |
+
.preview-tab {
|
594 |
+
color: #f5f5f5 !important;
|
595 |
+
background: #18181f !important;
|
596 |
+
}
|
597 |
+
|
598 |
+
/* For light mode, override with a media query or a .light class if you support it */
|
599 |
+
body.light .sidebar-section h3,
|
600 |
+
body.light .sidebar-section {
|
601 |
+
color: #1976d2 !important;
|
602 |
+
}
|
603 |
+
body.light .sidebar-section ul,
|
604 |
+
body.light .sidebar-section li {
|
605 |
+
color: #222 !important;
|
606 |
+
}
|
607 |
+
body.light .code-tabs .tab-nav .tab-nav-btn,
|
608 |
+
body.light .code-tabs .tab-nav .tab-nav-btn.selected {
|
609 |
+
color: #222 !important;
|
610 |
+
}
|
611 |
+
body.light .preview-tab {
|
612 |
+
color: #222 !important;
|
613 |
+
background: #fff !important;
|
614 |
}
|
app.py
CHANGED
@@ -7,10 +7,6 @@ import base64
|
|
7 |
import gradio as gr
|
8 |
from huggingface_hub import InferenceClient
|
9 |
|
10 |
-
import modelscope_studio.components.base as ms
|
11 |
-
import modelscope_studio.components.legacy as legacy
|
12 |
-
import modelscope_studio.components.antd as antd
|
13 |
-
|
14 |
# Configuration
|
15 |
SystemPrompt = """You are a helpful coding assistant. You help users create applications by generating code based on their requirements.
|
16 |
When asked to create an application, you should:
|
@@ -150,12 +146,12 @@ def remove_code_block(text):
|
|
150 |
extracted = match.group(1).strip()
|
151 |
return extracted
|
152 |
# If no code block is found, check if the entire text is HTML
|
153 |
-
if text.strip().startswith('<!DOCTYPE html>') or text.strip().startswith('<html'):
|
154 |
return text.strip()
|
155 |
return text.strip()
|
156 |
|
157 |
def history_render(history: History):
|
158 |
-
return gr.update(
|
159 |
|
160 |
def clear_history():
|
161 |
return []
|
@@ -267,155 +263,203 @@ def demo_card_click(e: gr.EventData):
|
|
267 |
# Return the first demo description as fallback
|
268 |
return DEMO_LIST[0]['description']
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
# Main application
|
271 |
-
with gr.Blocks(css_paths="app.css") as demo:
|
272 |
history = gr.State([])
|
273 |
setting = gr.State({
|
274 |
"system": SystemPrompt,
|
275 |
})
|
276 |
-
current_model = gr.State(AVAILABLE_MODELS[
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
stream=True,
|
375 |
-
max_tokens=5000 # Higher max_tokens for more complete applications while maintaining reasonable speed
|
376 |
)
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
yield {
|
383 |
-
code_output: content,
|
384 |
-
state_tab: gr.update(active_key="loading"),
|
385 |
-
code_drawer: gr.update(open=True),
|
386 |
-
}
|
387 |
-
|
388 |
-
# Final response
|
389 |
-
_history = messages_to_history(messages + [{
|
390 |
-
'role': 'assistant',
|
391 |
-
'content': content
|
392 |
-
}])
|
393 |
-
|
394 |
-
yield {
|
395 |
-
code_output: content,
|
396 |
-
history: _history,
|
397 |
-
sandbox: send_to_sandbox(remove_code_block(content)),
|
398 |
-
state_tab: gr.update(active_key="render"),
|
399 |
-
code_drawer: gr.update(open=False),
|
400 |
-
}
|
401 |
-
|
402 |
-
except Exception as e:
|
403 |
-
error_message = f"Error: {str(e)}"
|
404 |
-
yield {
|
405 |
-
code_output: error_message,
|
406 |
-
state_tab: gr.update(active_key="empty"),
|
407 |
-
code_drawer: gr.update(open=True),
|
408 |
-
}
|
409 |
-
|
410 |
-
btn.click(
|
411 |
-
generation_code,
|
412 |
-
inputs=[input, image_input, setting, history, current_model],
|
413 |
-
outputs=[code_output, history, sandbox, state_tab, code_drawer]
|
414 |
)
|
415 |
-
|
416 |
-
clear_btn.click(clear_history, inputs=[], outputs=[history])
|
417 |
-
|
418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
if __name__ == "__main__":
|
421 |
demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
|
|
|
7 |
import gradio as gr
|
8 |
from huggingface_hub import InferenceClient
|
9 |
|
|
|
|
|
|
|
|
|
10 |
# Configuration
|
11 |
SystemPrompt = """You are a helpful coding assistant. You help users create applications by generating code based on their requirements.
|
12 |
When asked to create an application, you should:
|
|
|
146 |
extracted = match.group(1).strip()
|
147 |
return extracted
|
148 |
# If no code block is found, check if the entire text is HTML
|
149 |
+
if text.strip().startswith('<!DOCTYPE html>') or text.strip().startswith('<html') or text.strip().startswith('<'):
|
150 |
return text.strip()
|
151 |
return text.strip()
|
152 |
|
153 |
def history_render(history: History):
|
154 |
+
return gr.update(visible=True), history
|
155 |
|
156 |
def clear_history():
|
157 |
return []
|
|
|
263 |
# Return the first demo description as fallback
|
264 |
return DEMO_LIST[0]['description']
|
265 |
|
266 |
+
def generation_code(query: Optional[str], image: Optional[gr.Image], _setting: Dict[str, str], _history: Optional[History], _current_model: Dict):
|
267 |
+
if query is None:
|
268 |
+
query = ''
|
269 |
+
if _history is None:
|
270 |
+
_history = []
|
271 |
+
messages = history_to_messages(_history, _setting['system'])
|
272 |
+
if image is not None:
|
273 |
+
messages.append(create_multimodal_message(query, image))
|
274 |
+
else:
|
275 |
+
messages.append({'role': 'user', 'content': query})
|
276 |
+
try:
|
277 |
+
completion = client.chat.completions.create(
|
278 |
+
model=_current_model["id"],
|
279 |
+
messages=messages,
|
280 |
+
stream=True,
|
281 |
+
max_tokens=5000
|
282 |
+
)
|
283 |
+
content = ""
|
284 |
+
for chunk in completion:
|
285 |
+
if chunk.choices[0].delta.content:
|
286 |
+
content += chunk.choices[0].delta.content
|
287 |
+
clean_code = remove_code_block(content)
|
288 |
+
yield {
|
289 |
+
code_output: clean_code,
|
290 |
+
status_indicator: '<div class="status-indicator generating" id="status">Generating code...</div>',
|
291 |
+
}
|
292 |
+
_history = messages_to_history(messages + [{
|
293 |
+
'role': 'assistant',
|
294 |
+
'content': content
|
295 |
+
}])
|
296 |
+
yield {
|
297 |
+
code_output: remove_code_block(content),
|
298 |
+
history: _history,
|
299 |
+
sandbox: send_to_sandbox(remove_code_block(content)),
|
300 |
+
status_indicator: '<div class="status-indicator success" id="status">Code generated successfully!</div>',
|
301 |
+
}
|
302 |
+
except Exception as e:
|
303 |
+
error_message = f"Error: {str(e)}"
|
304 |
+
yield {
|
305 |
+
code_output: error_message,
|
306 |
+
status_indicator: '<div class="status-indicator error" id="status">Error generating code</div>',
|
307 |
+
}
|
308 |
+
|
309 |
# Main application
|
310 |
+
with gr.Blocks(css_paths="app.css", title="AnyCoder - AI Code Generator") as demo:
|
311 |
history = gr.State([])
|
312 |
setting = gr.State({
|
313 |
"system": SystemPrompt,
|
314 |
})
|
315 |
+
current_model = gr.State(AVAILABLE_MODELS[0])
|
316 |
+
current_model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[0]['name']}", elem_classes="model-display")
|
317 |
+
open_panel = gr.State(None)
|
318 |
+
|
319 |
+
# Define shared components FIRST so they can be referenced everywhere
|
320 |
+
with gr.Row():
|
321 |
+
# Sidebar
|
322 |
+
with gr.Column(scale=0, min_width=340, elem_classes="sidebar"):
|
323 |
+
gr.HTML("""
|
324 |
+
<div class="sidebar-header">
|
325 |
+
<img src="https://huggingface.co/spaces/akhaliq/anycoder/resolve/main/Animated_Logo_Video_Ready.gif" width="48px" />
|
326 |
+
<h1>AnyCoder</h1>
|
327 |
+
<div class="sidebar-desc">AI-Powered Code Generator</div>
|
328 |
+
</div>
|
329 |
+
""")
|
330 |
+
input = gr.Textbox(
|
331 |
+
label="Describe your application",
|
332 |
+
placeholder="e.g., Create a todo app with add, delete, and mark as complete functionality",
|
333 |
+
lines=2,
|
334 |
+
elem_classes="code-input"
|
335 |
+
)
|
336 |
+
image_input = gr.Image(
|
337 |
+
label="Upload UI design image (ERNIE-4.5-VL only)",
|
338 |
+
visible=False,
|
339 |
+
elem_classes="image-input"
|
340 |
+
)
|
341 |
+
with gr.Row():
|
342 |
+
btn = gr.Button("Generate", variant="primary", size="sm", elem_classes="generate-btn")
|
343 |
+
clear_btn = gr.Button("Clear", variant="secondary", size="sm", elem_classes="clear-btn")
|
344 |
+
gr.HTML("""
|
345 |
+
<div class="sidebar-section">
|
346 |
+
<h3>How it works</h3>
|
347 |
+
<ul>
|
348 |
+
<li>Describe your app or UI in plain English</li>
|
349 |
+
<li>Optionally upload a UI image (for ERNIE model)</li>
|
350 |
+
<li>Click Generate to get code and preview</li>
|
351 |
+
</ul>
|
352 |
+
</div>
|
353 |
+
""")
|
354 |
+
gr.HTML("<div class='sidebar-section'><h3>Quick Examples</h3></div>")
|
355 |
+
for i, demo_item in enumerate(DEMO_LIST[:5]):
|
356 |
+
demo_card = gr.Button(
|
357 |
+
value=demo_item['title'],
|
358 |
+
variant="secondary",
|
359 |
+
size="sm",
|
360 |
+
elem_classes="quick-example-btn sidebar-btn"
|
361 |
+
)
|
362 |
+
demo_card.click(
|
363 |
+
fn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),
|
364 |
+
outputs=input
|
365 |
+
)
|
366 |
+
gr.HTML("<hr style='margin: 16px 0;'>")
|
367 |
+
with gr.Row():
|
368 |
+
modelBtn = gr.Button("🤖 Model", variant="secondary", size="sm", elem_classes="sidebar-btn")
|
369 |
+
settingPromptBtn = gr.Button("⚙️ Prompt", variant="secondary", size="sm", elem_classes="sidebar-btn")
|
370 |
+
historyBtn = gr.Button("📜 History", variant="secondary", size="sm", elem_classes="sidebar-btn")
|
371 |
+
# Place modals/drawers at the end of the sidebar so they overlay the lower part
|
372 |
+
with gr.Group(visible=False, elem_classes="modal") as system_prompt_modal:
|
373 |
+
gr.HTML("<h3>System Prompt Configuration</h3>")
|
374 |
+
systemPromptInput = gr.Textbox(
|
375 |
+
value=SystemPrompt,
|
376 |
+
label="System Prompt",
|
377 |
+
lines=10,
|
378 |
+
elem_classes="modal-input"
|
379 |
+
)
|
380 |
+
with gr.Row():
|
381 |
+
modal_ok_btn = gr.Button("Save", variant="primary")
|
382 |
+
modal_cancel_btn = gr.Button("Cancel", variant="secondary")
|
383 |
+
|
384 |
+
with gr.Group(visible=False, elem_classes="modal") as model_modal:
|
385 |
+
gr.HTML("<h3>Select AI Model</h3>")
|
386 |
+
with gr.Row(elem_classes="model-select-row"):
|
387 |
+
for i, model in enumerate(AVAILABLE_MODELS):
|
388 |
+
model_select_btn = gr.Button(
|
389 |
+
value=model['name'],
|
390 |
+
variant="secondary",
|
391 |
+
size="sm",
|
392 |
+
elem_classes="model-card-btn"
|
393 |
+
)
|
394 |
+
model_select_btn.click(
|
395 |
+
lambda m=model: (m, gr.update(visible=False), f"**Model:** {m['name']}", update_image_input_visibility(m)),
|
396 |
+
outputs=[current_model, model_modal, current_model_display, image_input]
|
397 |
+
)
|
398 |
+
|
399 |
+
with gr.Group(visible=False, elem_classes="drawer") as history_drawer:
|
400 |
+
gr.HTML("<h3>Generation History</h3>")
|
401 |
+
history_output = gr.Chatbot(show_label=False, height=400, elem_classes="history_chatbot")
|
402 |
+
# Main area
|
403 |
+
with gr.Column(scale=1, min_width=700, elem_classes="main-area"):
|
404 |
+
with gr.Row():
|
405 |
+
current_model_display
|
406 |
+
with gr.Tabs(elem_classes="code-tabs") as tabs:
|
407 |
+
with gr.Tab("Code Editor", elem_classes="code-tab"):
|
408 |
+
code_output = gr.Code(
|
409 |
+
language="html",
|
410 |
+
lines=25,
|
411 |
+
interactive=False,
|
412 |
+
elem_classes="code-editor"
|
|
|
|
|
413 |
)
|
414 |
+
with gr.Tab("Live Preview", elem_classes="preview-tab"):
|
415 |
+
sandbox = gr.HTML(elem_classes="html_content")
|
416 |
+
status_indicator = gr.HTML(
|
417 |
+
'<div class="status-indicator" id="status">Ready to generate code</div>',
|
418 |
+
elem_classes="status-bar"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
)
|
|
|
|
|
|
|
420 |
|
421 |
+
# Event handlers
|
422 |
+
settingPromptBtn.click(
|
423 |
+
fn=lambda current: toggle_panel(current, "prompt"),
|
424 |
+
inputs=[open_panel],
|
425 |
+
outputs=[system_prompt_modal, model_modal, history_drawer, open_panel]
|
426 |
+
)
|
427 |
+
modelBtn.click(
|
428 |
+
fn=lambda current: toggle_panel(current, "model"),
|
429 |
+
inputs=[open_panel],
|
430 |
+
outputs=[system_prompt_modal, model_modal, history_drawer, open_panel]
|
431 |
+
)
|
432 |
+
historyBtn.click(
|
433 |
+
fn=lambda current, history: (*toggle_panel(current, "history")[:3], history, toggle_panel(current, "history")[3]),
|
434 |
+
inputs=[open_panel, history],
|
435 |
+
outputs=[system_prompt_modal, model_modal, history_drawer, history_output, open_panel]
|
436 |
+
)
|
437 |
+
modal_ok_btn.click(
|
438 |
+
lambda input: ({"system": input}, gr.update(visible=False)),
|
439 |
+
inputs=[systemPromptInput],
|
440 |
+
outputs=[setting, system_prompt_modal]
|
441 |
+
)
|
442 |
+
modal_cancel_btn.click(lambda: gr.update(visible=False), outputs=[system_prompt_modal])
|
443 |
+
btn.click(
|
444 |
+
generation_code,
|
445 |
+
inputs=[input, image_input, setting, history, current_model],
|
446 |
+
outputs=[code_output, history, sandbox, status_indicator]
|
447 |
+
)
|
448 |
+
clear_btn.click(clear_history, outputs=[history])
|
449 |
+
|
450 |
+
def toggle_panel(current, panel):
|
451 |
+
# If the requested panel is already open, close all
|
452 |
+
if current == panel:
|
453 |
+
return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), None)
|
454 |
+
# Otherwise, open the requested panel and close others
|
455 |
+
if panel == "prompt":
|
456 |
+
return (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), "prompt")
|
457 |
+
elif panel == "model":
|
458 |
+
return (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), "model")
|
459 |
+
elif panel == "history":
|
460 |
+
return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), "history")
|
461 |
+
else:
|
462 |
+
return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), None)
|
463 |
|
464 |
if __name__ == "__main__":
|
465 |
demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
|
requirements.txt
CHANGED
@@ -1,3 +1,2 @@
|
|
1 |
-
modelscope_studio
|
2 |
git+https://github.com/huggingface/huggingface_hub.git
|
3 |
gradio[oauth]
|
|
|
|
|
1 |
git+https://github.com/huggingface/huggingface_hub.git
|
2 |
gradio[oauth]
|