vsj0702 commited on
Commit
73d1f25
·
verified ·
1 Parent(s): 6888b36

Updating to select multi language

Browse files
Files changed (1) hide show
  1. app.py +32 -10
app.py CHANGED
@@ -4,24 +4,41 @@ from utils import execute_code
4
  from chatbot import render_chatbot
5
  from layout import init_session_state, apply_theme
6
 
 
7
  st.set_page_config(page_title="Pro Code Playground", page_icon="💻", layout="wide")
8
  init_session_state()
9
 
10
- theme_choice = st.radio("Theme", options=["☀️", "🌙"], horizontal=True, label_visibility="collapsed")
11
- st.session_state.dark_mode = (theme_choice == "🌙")
12
- colors, ace_theme = apply_theme()
13
-
14
  st.title("Pro Code Playground")
15
- st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
 
 
 
 
 
 
 
 
 
 
16
 
 
 
 
 
 
 
 
 
17
  gen, bot = st.columns((2, 1), gap="large")
18
 
19
  with gen:
20
  st.subheader("Editor")
 
21
  code = st_ace.st_ace(
22
  value=st.session_state.code,
23
- placeholder="Start typing your Python code…",
24
- language="python",
25
  theme=ace_theme,
26
  keybinding="vscode",
27
  font_size=14,
@@ -35,7 +52,7 @@ with gen:
35
  st.session_state.code = code
36
 
37
  user_input = st.text_area(
38
- label="📅 Input (stdin)",
39
  value=st.session_state.stdin,
40
  placeholder="Enter input() values here, one per line",
41
  height=100,
@@ -45,7 +62,11 @@ with gen:
45
  st.session_state.stdin = user_input
46
 
47
  if st.button("▶️ Run"):
48
- out, err, exc = execute_code(st.session_state.code, st.session_state.stdin)
 
 
 
 
49
  st.session_state.code_output = out
50
  st.session_state.error_output = err or exc
51
 
@@ -63,8 +84,9 @@ with bot:
63
  st.session_state.get("error_output", "")
64
  )
65
 
 
66
  st.markdown("""
67
  <div style='text-align:center; margin-top:1rem; opacity:0.6;'>
68
  Built with ❤️ & Streamlit by Vaibhav
69
  </div>
70
- """, unsafe_allow_html=True)
 
4
  from chatbot import render_chatbot
5
  from layout import init_session_state, apply_theme
6
 
7
+ # Page Setup
8
  st.set_page_config(page_title="Pro Code Playground", page_icon="💻", layout="wide")
9
  init_session_state()
10
 
11
+ # Header
 
 
 
12
  st.title("Pro Code Playground")
13
+ st.markdown("Write, execute & export multi-language snippets, with built‑in AI assistance.")
14
+
15
+ # Row for language selector + theme toggle
16
+ lang_col, spacer, theme_col = st.columns([3, 6, 1])
17
+ with lang_col:
18
+ lang = st.selectbox(
19
+ "Language",
20
+ options=["Python", "C", "C++", "Java", "JavaScript", "C#"],
21
+ index=0,
22
+ key="language"
23
+ )
24
 
25
+ with theme_col:
26
+ theme_choice = st.radio("Theme", options=["☀️", "🌙"], horizontal=True, label_visibility="collapsed")
27
+ st.session_state.dark_mode = (theme_choice == "🌙")
28
+
29
+ # Apply selected theme
30
+ colors, ace_theme = apply_theme()
31
+
32
+ # Editor + Chatbot Columns
33
  gen, bot = st.columns((2, 1), gap="large")
34
 
35
  with gen:
36
  st.subheader("Editor")
37
+
38
  code = st_ace.st_ace(
39
  value=st.session_state.code,
40
+ placeholder=f"Start typing your {lang} code…",
41
+ language=lang.lower() if lang != "C++" else "c_cpp", # Ace language codes
42
  theme=ace_theme,
43
  keybinding="vscode",
44
  font_size=14,
 
52
  st.session_state.code = code
53
 
54
  user_input = st.text_area(
55
+ label="📥 Input (stdin)",
56
  value=st.session_state.stdin,
57
  placeholder="Enter input() values here, one per line",
58
  height=100,
 
62
  st.session_state.stdin = user_input
63
 
64
  if st.button("▶️ Run"):
65
+ out, err, exc = execute_code(
66
+ code=st.session_state.code,
67
+ stdin=st.session_state.stdin,
68
+ language=lang.lower()
69
+ )
70
  st.session_state.code_output = out
71
  st.session_state.error_output = err or exc
72
 
 
84
  st.session_state.get("error_output", "")
85
  )
86
 
87
+ # Footer
88
  st.markdown("""
89
  <div style='text-align:center; margin-top:1rem; opacity:0.6;'>
90
  Built with ❤️ & Streamlit by Vaibhav
91
  </div>
92
+ """, unsafe_allow_html=True)