Spaces:
Running
Running
owenkaplinsky
commited on
Commit
·
938d259
1
Parent(s):
3974968
Move Gradio server creation location
Browse files- project/src/generators/python.js +0 -11
- project/src/index.js +77 -1
project/src/generators/python.js
CHANGED
|
@@ -164,17 +164,6 @@ forBlock['create_mcp'] = function (block, generator) {
|
|
| 164 |
}
|
| 165 |
}
|
| 166 |
|
| 167 |
-
// Create Gradio Interface with dynamic I/O
|
| 168 |
-
// Always include outputs parameter, use empty list if no outputs
|
| 169 |
-
code += `\ndemo = gr.Interface(
|
| 170 |
-
fn=create_mcp,
|
| 171 |
-
inputs=[${gradioInputs.join(', ')}],
|
| 172 |
-
outputs=[${gradioOutputs.join(', ')}],
|
| 173 |
-
)
|
| 174 |
-
|
| 175 |
-
demo.launch(mcp_server=True)
|
| 176 |
-
`;
|
| 177 |
-
|
| 178 |
return code;
|
| 179 |
};
|
| 180 |
|
|
|
|
| 164 |
}
|
| 165 |
}
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
return code;
|
| 168 |
};
|
| 169 |
|
project/src/index.js
CHANGED
|
@@ -1284,7 +1284,83 @@ const updateCode = () => {
|
|
| 1284 |
code = "from sympy import isprime\n\n" + code;
|
| 1285 |
}
|
| 1286 |
|
| 1287 |
-
code = "import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1288 |
|
| 1289 |
if (codeEl) {
|
| 1290 |
codeEl.textContent = code;
|
|
|
|
| 1284 |
code = "from sympy import isprime\n\n" + code;
|
| 1285 |
}
|
| 1286 |
|
| 1287 |
+
code = "import gradio as gr" + code;
|
| 1288 |
+
|
| 1289 |
+
// Extract input and output counts from the create_mcp block to build Gradio interface
|
| 1290 |
+
const mcpBlocks = ws.getBlocksByType('create_mcp');
|
| 1291 |
+
if (mcpBlocks.length > 0) {
|
| 1292 |
+
const mcpBlock = mcpBlocks[0];
|
| 1293 |
+
|
| 1294 |
+
// Build list of Gradio input components based on input types
|
| 1295 |
+
const gradioInputs = [];
|
| 1296 |
+
if (mcpBlock.inputCount_ && mcpBlock.inputCount_ > 0 && mcpBlock.getInput('X0')) {
|
| 1297 |
+
for (let k = 0; k < mcpBlock.inputCount_; k++) {
|
| 1298 |
+
const type = mcpBlock.inputTypes_[k];
|
| 1299 |
+
switch (type) {
|
| 1300 |
+
case 'integer':
|
| 1301 |
+
gradioInputs.push('gr.Number()');
|
| 1302 |
+
break;
|
| 1303 |
+
case 'float':
|
| 1304 |
+
gradioInputs.push('gr.Number()');
|
| 1305 |
+
break;
|
| 1306 |
+
case 'string':
|
| 1307 |
+
gradioInputs.push('gr.Textbox()');
|
| 1308 |
+
break;
|
| 1309 |
+
case 'list':
|
| 1310 |
+
gradioInputs.push('gr.Dataframe()');
|
| 1311 |
+
break;
|
| 1312 |
+
case 'boolean':
|
| 1313 |
+
gradioInputs.push('gr.Checkbox()');
|
| 1314 |
+
break;
|
| 1315 |
+
case 'any':
|
| 1316 |
+
gradioInputs.push('gr.JSON()');
|
| 1317 |
+
break;
|
| 1318 |
+
default:
|
| 1319 |
+
gradioInputs.push('gr.Textbox()');
|
| 1320 |
+
}
|
| 1321 |
+
}
|
| 1322 |
+
}
|
| 1323 |
+
|
| 1324 |
+
// Build list of Gradio output components based on output types
|
| 1325 |
+
const gradioOutputs = [];
|
| 1326 |
+
if (mcpBlock.outputCount_ && mcpBlock.outputCount_ > 0 && mcpBlock.getInput('R0')) {
|
| 1327 |
+
for (let k = 0; k < mcpBlock.outputCount_; k++) {
|
| 1328 |
+
const type = mcpBlock.outputTypes_[k];
|
| 1329 |
+
switch (type) {
|
| 1330 |
+
case 'integer':
|
| 1331 |
+
gradioOutputs.push('gr.Number()');
|
| 1332 |
+
break;
|
| 1333 |
+
case 'float':
|
| 1334 |
+
gradioOutputs.push('gr.Number()');
|
| 1335 |
+
break;
|
| 1336 |
+
case 'string':
|
| 1337 |
+
gradioOutputs.push('gr.Textbox()');
|
| 1338 |
+
break;
|
| 1339 |
+
case 'list':
|
| 1340 |
+
gradioOutputs.push('gr.Dataframe()');
|
| 1341 |
+
break;
|
| 1342 |
+
case 'boolean':
|
| 1343 |
+
gradioOutputs.push('gr.Checkbox()');
|
| 1344 |
+
break;
|
| 1345 |
+
case 'any':
|
| 1346 |
+
gradioOutputs.push('gr.JSON()');
|
| 1347 |
+
break;
|
| 1348 |
+
default:
|
| 1349 |
+
gradioOutputs.push('gr.Textbox()');
|
| 1350 |
+
}
|
| 1351 |
+
}
|
| 1352 |
+
}
|
| 1353 |
+
|
| 1354 |
+
// Append Gradio interface code at the very end
|
| 1355 |
+
code += `\ndemo = gr.Interface(
|
| 1356 |
+
fn=create_mcp,
|
| 1357 |
+
inputs=[${gradioInputs.join(', ')}],
|
| 1358 |
+
outputs=[${gradioOutputs.join(', ')}],
|
| 1359 |
+
)
|
| 1360 |
+
|
| 1361 |
+
demo.launch(mcp_server=True)
|
| 1362 |
+
`;
|
| 1363 |
+
}
|
| 1364 |
|
| 1365 |
if (codeEl) {
|
| 1366 |
codeEl.textContent = code;
|