Luis-Filipe commited on
Commit
9309476
verified
1 Parent(s): 812f824

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -37
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
2
  import subprocess
3
  import tempfile
4
  import os
@@ -41,45 +41,30 @@ def run_pcbasic_code(code, timeout=60):
41
  except Exception as e:
42
  return f"Erro: {str(e)}", None
43
 
44
- def process_basic_code(code):
45
- """Processa o c贸digo BASIC e prepara as sa铆das para exibi莽茫o no Gradio."""
46
- text, img = run_pcbasic_code(code)
 
 
 
 
 
 
 
47
 
48
  if img:
49
  img_byte = io.BytesIO()
50
  img.save(img_byte, format="PNG")
51
- return text, img_byte.getvalue()
52
- return text, None
53
 
54
- # Configura莽茫o da interface Gradio
55
- with gr.Blocks(title="PCBasic Interpreter") as demo:
56
- gr.Markdown("# PCBasic Interpreter Online")
57
-
58
- with gr.Row():
59
- with gr.Column():
60
- code_input = gr.Textbox(
61
- label="C贸digo BASIC",
62
- placeholder="Digite seu c贸digo aqui...",
63
- lines=15
64
- )
65
- run_btn = gr.Button("Executar")
66
- with gr.Column():
67
- text_out = gr.Textbox(label="Sa铆da de Texto", lines=10)
68
- image_out = gr.Image(label="Sa铆da Gr谩fica", type="filepath")
69
-
70
- examples = gr.Examples(
71
- examples=[
72
- ["10 PRINT \"OL脕 MUNDO!\""],
73
- ["10 FOR I=1 TO 10\n20 PRINT I*2\n30 NEXT I"],
74
- ["10 SCREEN 1\n20 CIRCLE (160,100),50\n30 PAINT (160,100)"]
75
- ],
76
- inputs=code_input
77
- )
78
-
79
- run_btn.click(
80
- fn=process_basic_code,
81
- inputs=code_input,
82
- outputs=[text_out, image_out]
83
- )
84
 
85
- demo.launch()
 
 
 
1
+ import streamlit as st
2
  import subprocess
3
  import tempfile
4
  import os
 
41
  except Exception as e:
42
  return f"Erro: {str(e)}", None
43
 
44
+ # Configura莽茫o da interface Streamlit
45
+ st.title("PCBasic Interpreter Online")
46
+
47
+ code_input = st.text_area("C贸digo BASIC", placeholder="Digite seu c贸digo aqui...", height=300)
48
+ run_btn = st.button("Executar")
49
+
50
+ if run_btn:
51
+ text_output, img = run_pcbasic_code(code_input)
52
+
53
+ st.text_area("Sa铆da de Texto", text_output, height=200)
54
 
55
  if img:
56
  img_byte = io.BytesIO()
57
  img.save(img_byte, format="PNG")
58
+ st.image(img_byte.getvalue(), caption="Sa铆da Gr谩fica")
 
59
 
60
+ # Exemplos de c贸digo BASIC
61
+ st.sidebar.title("Exemplos")
62
+ examples = [
63
+ "10 PRINT \"OL脕 MUNDO!\"",
64
+ "10 FOR I=1 TO 10\n20 PRINT I*2\n30 NEXT I",
65
+ "10 SCREEN 1\n20 CIRCLE (160,100),50\n30 PAINT (160,100)"
66
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
+ for example in examples:
69
+ if st.sidebar.button(example):
70
+ code_input = st.text_area("C贸digo BASIC", example, height=300)