Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -11,12 +11,13 @@ def run_pcbasic_code(code, timeout=60):
|
|
| 11 |
code_path = os.path.join(tmpdir, "code.bas")
|
| 12 |
img_path = os.path.join(tmpdir, "output.png")
|
| 13 |
|
| 14 |
-
#
|
| 15 |
with open(code_path, "w") as f:
|
| 16 |
f.write(code)
|
| 17 |
|
| 18 |
env = os.environ.copy()
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
try:
|
| 22 |
process = subprocess.run(
|
|
@@ -25,7 +26,7 @@ def run_pcbasic_code(code, timeout=60):
|
|
| 25 |
f"--run={code_path}",
|
| 26 |
"--interface=sdl2",
|
| 27 |
"--video=SDL2",
|
| 28 |
-
#
|
| 29 |
"--output", img_path
|
| 30 |
],
|
| 31 |
env=env,
|
|
@@ -48,7 +49,6 @@ def process_basic_code(code):
|
|
| 48 |
"""Processa o código BASIC e prepara as saídas para exibição no Gradio."""
|
| 49 |
text, img = run_pcbasic_code(code)
|
| 50 |
|
| 51 |
-
# Converte a imagem PIL para um formato de bytes compatível com Gradio
|
| 52 |
if img:
|
| 53 |
img_byte = io.BytesIO()
|
| 54 |
img.save(img_byte, format="PNG")
|
|
@@ -67,12 +67,10 @@ with gr.Blocks(title="PCBasic Interpreter") as demo:
|
|
| 67 |
lines=15
|
| 68 |
)
|
| 69 |
run_btn = gr.Button("Executar")
|
| 70 |
-
|
| 71 |
with gr.Column():
|
| 72 |
text_out = gr.Textbox(label="Saída de Texto", lines=10)
|
| 73 |
image_out = gr.Image(label="Saída Gráfica", type="filepath")
|
| 74 |
|
| 75 |
-
# Exemplos pré-definidos para facilitar o uso inicial
|
| 76 |
examples = gr.Examples(
|
| 77 |
examples=[
|
| 78 |
["10 PRINT \"OLÁ MUNDO!\""],
|
|
@@ -82,7 +80,6 @@ with gr.Blocks(title="PCBasic Interpreter") as demo:
|
|
| 82 |
inputs=code_input
|
| 83 |
)
|
| 84 |
|
| 85 |
-
# Conecta o botão à função de processamento do código BASIC
|
| 86 |
run_btn.click(
|
| 87 |
fn=process_basic_code,
|
| 88 |
inputs=code_input,
|
|
|
|
| 11 |
code_path = os.path.join(tmpdir, "code.bas")
|
| 12 |
img_path = os.path.join(tmpdir, "output.png")
|
| 13 |
|
| 14 |
+
# Salva o código BASIC num arquivo temporário
|
| 15 |
with open(code_path, "w") as f:
|
| 16 |
f.write(code)
|
| 17 |
|
| 18 |
env = os.environ.copy()
|
| 19 |
+
# Força o SDL a usar o driver 'dummy' para não abrir uma janela nativa
|
| 20 |
+
env["SDL_VIDEODRIVER"] = "dummy"
|
| 21 |
|
| 22 |
try:
|
| 23 |
process = subprocess.run(
|
|
|
|
| 26 |
f"--run={code_path}",
|
| 27 |
"--interface=sdl2",
|
| 28 |
"--video=SDL2",
|
| 29 |
+
# Remova a flag --fullscreen para não tentar abrir uma janela
|
| 30 |
"--output", img_path
|
| 31 |
],
|
| 32 |
env=env,
|
|
|
|
| 49 |
"""Processa o código BASIC e prepara as saídas para exibição no Gradio."""
|
| 50 |
text, img = run_pcbasic_code(code)
|
| 51 |
|
|
|
|
| 52 |
if img:
|
| 53 |
img_byte = io.BytesIO()
|
| 54 |
img.save(img_byte, format="PNG")
|
|
|
|
| 67 |
lines=15
|
| 68 |
)
|
| 69 |
run_btn = gr.Button("Executar")
|
|
|
|
| 70 |
with gr.Column():
|
| 71 |
text_out = gr.Textbox(label="Saída de Texto", lines=10)
|
| 72 |
image_out = gr.Image(label="Saída Gráfica", type="filepath")
|
| 73 |
|
|
|
|
| 74 |
examples = gr.Examples(
|
| 75 |
examples=[
|
| 76 |
["10 PRINT \"OLÁ MUNDO!\""],
|
|
|
|
| 80 |
inputs=code_input
|
| 81 |
)
|
| 82 |
|
|
|
|
| 83 |
run_btn.click(
|
| 84 |
fn=process_basic_code,
|
| 85 |
inputs=code_input,
|