mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-19 04:17:52 +00:00
zzz
This commit is contained in:
parent
419603b593
commit
fa7f180cb7
53
web/src/components/IPythonConsole.vue
Normal file
53
web/src/components/IPythonConsole.vue
Normal file
@ -0,0 +1,53 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>IPython Console</h2>
|
||||
<textarea v-model="input"></textarea>
|
||||
<button @click="execute">Execute</button>
|
||||
<pre v-if="result">{{ result }}</pre>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as IPython from 'jupyter';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
input: '',
|
||||
result: '',
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
const widget = this.$refs.console;
|
||||
if (widget) {
|
||||
// Initialize the IPython console with the existing DOM node.
|
||||
IPython.Widget(widget);
|
||||
|
||||
// Connect the console's output area to the textarea for reading/writing.
|
||||
widget.editor.getOutputArea().attachTo(this.$refs.input);
|
||||
|
||||
// Listen for changes in the textarea.
|
||||
this.$watch('input', () => {
|
||||
if (this.input === '') return;
|
||||
this.execute();
|
||||
});
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
execute() {
|
||||
const widget = this.$refs.console;
|
||||
const code = this.input;
|
||||
|
||||
// Execute the code and display the results.
|
||||
widget.executeCode(code, null, (err, result) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
this.result = '';
|
||||
} else {
|
||||
this.result = result;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user