upgraded ui

This commit is contained in:
Saifeddine ALOUI 2024-02-06 00:57:00 +01:00
parent 51a96542cf
commit a4db558bb6
7 changed files with 53 additions and 6 deletions

View File

@ -28,6 +28,8 @@ from utilities.execution_engines.python_execution_engine import execute_python
from utilities.execution_engines.latex_execution_engine import execute_latex
from utilities.execution_engines.shell_execution_engine import execute_bash
from utilities.execution_engines.javascript_execution_engine import execute_javascript
from utilities.execution_engines.html_execution_engine import execute_html
from utilities.execution_engines.mermaid_execution_engine import execute_mermaid
from utilities.execution_engines.graphviz_execution_engine import execute_graphviz
@ -64,6 +66,11 @@ async def execute_code(request: Request):
ASCIIColors.info("Executing javascript code:")
ASCIIColors.yellow(code)
return execute_javascript(code, discussion_id, message_id)
if language in ["html","html5"]:
ASCIIColors.info("Executing javascript code:")
ASCIIColors.yellow(code)
return execute_html(code, discussion_id, message_id)
elif language=="latex":
ASCIIColors.info("Executing latex code:")
ASCIIColors.yellow(code)

View File

@ -0,0 +1,42 @@
"""
project: lollms_webui
file: shell_execution_engine.py
author: ParisNeo
description:
This is a utility for executing python code
"""
from lollms_webui import LOLLMSWebUI
from ascii_colors import get_trace_exception, trace_exception
import time
import subprocess
import json
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
def build_html_output(code, ifram_name="unnamed"):
"""
This function creates an HTML5 iframe with the given HTML content and iframe name.
Args:
html (str): The HTML content to be displayed in the iframe.
ifram_name (str, optional): The name of the iframe. Defaults to "unnamed".
Returns:
str: The HTML string for the iframe.
"""
# Start the timer.
start_time = time.time()
rendered = "\n".join([
'<div style="width: 100%; margin: 0 auto;">',
f'<iframe id="{ifram_name}" srcdoc=\'',
code.replace("'","\""),
'\' style="width: 100%; height: 600px; border: none;"></iframe>',
'</div>'
]
)
execution_time = time.time() - start_time
return {"output": rendered, "execution_time": execution_time}
def execute_html(code, discussion_id, message_id):
return build_html_output(code)

View File

@ -33,8 +33,6 @@ def build_javascript_output(code, ifram_name="unnamed"):
'<script>',
code,
'</script>',
'<div style=\'text-align: center;\'>',
'</div>',
'" style="width: 100%; height: 600px; border: none;"></iframe>',
'</div>'
]

File diff suppressed because one or more lines are too long

2
web/dist/index.html vendored
View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-03f6cf4a.js"></script>
<script type="module" crossorigin src="/assets/index-de57e167.js"></script>
<link rel="stylesheet" href="/assets/index-d55ae77e.css">
</head>
<body>

View File

@ -7,7 +7,7 @@
class="px-2 py-1 ml-2 text-left p-2 text-sm font-medium rounded-lg hover:bg-primary dark:hover:bg-primary text-white text-xs transition-colors duration-200">
<i data-feather="copy"></i>
</button>
<button v-if="['python', 'sh', 'shell', 'bash', 'cmd', 'powershell', 'latex', 'mermaid', 'graphviz', 'dot', 'javascript'].includes(language)" ref="btn_code_exec" @click="executeCode" title="execute"
<button v-if="['python', 'sh', 'shell', 'bash', 'cmd', 'powershell', 'latex', 'mermaid', 'graphviz', 'dot', 'javascript', 'html', 'html5'].includes(language)" ref="btn_code_exec" @click="executeCode" title="execute"
class="px-2 py-1 ml-2 text-left p-2 text-sm font-medium bg-bg-dark-tone-panel dark:bg-bg-dark-tone rounded-lg hover:bg-primary dark:hover:bg-primary text-white text-xs transition-colors duration-200"
:class="isExecuting?'bg-green-500':''">
<i data-feather="play-circle"></i>

@ -1 +1 @@
Subproject commit 3a2c5c3995076d2a415e79c23439dee92cb049ad
Subproject commit e876bcee0d8fcacb309ce2acf833786143a438b8