vsj0702 commited on
Commit
a8a25ed
·
verified ·
1 Parent(s): 05ed529

working on refresh issue

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -12,9 +12,6 @@ init_session_state()
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
-
18
  # Define default code snippets
19
  DEFAULT_SNIPPETS = {
20
  "Python": '''a = int(input())\nb = int(input())\nprint("Sum:", a + b)''',
@@ -25,15 +22,19 @@ DEFAULT_SNIPPETS = {
25
  "C#": '''using System;\npublic class Program {\n public static void Main(string[] args) {\n int a = Convert.ToInt32(Console.ReadLine());\n int b = Convert.ToInt32(Console.ReadLine());\n Console.WriteLine("Sum: " + (a + b));\n }\n}'''
26
  }
27
 
28
- # Language dropdown
 
29
  with lang_col:
30
- selected_lang = st.selectbox(
31
- "Language",
32
- options=list(DEFAULT_SNIPPETS.keys()),
33
- index=0
34
- )
 
 
 
35
 
36
- # If language changed OR code was never set before, reset with default
37
  prev_lang = st.session_state.get("prev_language", "")
38
  if (
39
  selected_lang != prev_lang
@@ -43,28 +44,20 @@ if (
43
  ):
44
  st.session_state.code = DEFAULT_SNIPPETS[selected_lang]
45
 
46
- # Update language and previous language
47
- lang = selected_lang
48
- st.session_state.prev_language = lang
49
-
50
 
51
- with theme_col:
52
- theme_choice = st.radio("Theme", options=["☀️", "🌙"], horizontal=True, label_visibility="collapsed")
53
- st.session_state.dark_mode = (theme_choice == "🌙")
54
-
55
- # Apply selected theme
56
- colors, ace_theme = apply_theme()
57
-
58
- # Editor + Chatbot Columns
59
  gen, bot = st.columns((2, 1), gap="large")
60
-
61
  with gen:
62
  st.subheader("Editor")
63
 
64
  code = st_ace.st_ace(
65
- value=st.session_state.code,
66
  placeholder=f"Start typing your {lang} code…",
67
- language=lang.lower() if lang != "C++" else "c_cpp", # Ace language codes
68
  theme=ace_theme,
69
  keybinding="vscode",
70
  font_size=14,
 
12
  st.title("Pro Code Playground")
13
  st.markdown("Write, execute & export multi-language snippets, with built‑in AI assistance.")
14
 
 
 
 
15
  # Define default code snippets
16
  DEFAULT_SNIPPETS = {
17
  "Python": '''a = int(input())\nb = int(input())\nprint("Sum:", a + b)''',
 
22
  "C#": '''using System;\npublic class Program {\n public static void Main(string[] args) {\n int a = Convert.ToInt32(Console.ReadLine());\n int b = Convert.ToInt32(Console.ReadLine());\n Console.WriteLine("Sum: " + (a + b));\n }\n}'''
23
  }
24
 
25
+ # Language + Theme selection
26
+ lang_col, spacer, theme_col = st.columns([3, 6, 1])
27
  with lang_col:
28
+ selected_lang = st.selectbox("Language", list(DEFAULT_SNIPPETS.keys()), index=0)
29
+
30
+ with theme_col:
31
+ theme_choice = st.radio("Theme", options=["☀️", "🌙"], horizontal=True, label_visibility="collapsed")
32
+ st.session_state.dark_mode = (theme_choice == "🌙")
33
+
34
+ # Apply theme
35
+ colors, ace_theme = apply_theme()
36
 
37
+ # Set default code when language changes or editor is empty
38
  prev_lang = st.session_state.get("prev_language", "")
39
  if (
40
  selected_lang != prev_lang
 
44
  ):
45
  st.session_state.code = DEFAULT_SNIPPETS[selected_lang]
46
 
47
+ # Force update the Ace editor value
48
+ st.session_state["editor_code"] = st.session_state.code
49
+ st.session_state.prev_language = selected_lang
50
+ lang = selected_lang # Use `lang` everywhere below
51
 
52
+ # Editor + Chatbot layout
 
 
 
 
 
 
 
53
  gen, bot = st.columns((2, 1), gap="large")
 
54
  with gen:
55
  st.subheader("Editor")
56
 
57
  code = st_ace.st_ace(
58
+ value=st.session_state["editor_code"],
59
  placeholder=f"Start typing your {lang} code…",
60
+ language=lang.lower() if lang != "C++" else "c_cpp",
61
  theme=ace_theme,
62
  keybinding="vscode",
63
  font_size=14,