Spaces:
Sleeping
Sleeping
Fixed refresh issue
Browse files
app.py
CHANGED
|
@@ -12,8 +12,10 @@ 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 |
-
#
|
| 16 |
lang_col, spacer, theme_col = st.columns([3, 6, 1])
|
|
|
|
|
|
|
| 17 |
with lang_col:
|
| 18 |
lang = st.selectbox(
|
| 19 |
"Language",
|
|
@@ -22,7 +24,7 @@ with lang_col:
|
|
| 22 |
key="language"
|
| 23 |
)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
DEFAULT_SNIPPETS = {
|
| 27 |
"Python": '''a = int(input())\nb = int(input())\nprint("Sum:", a + b)''',
|
| 28 |
"C": '''#include <stdio.h>\nint main() {\n int a, b;\n scanf("%d %d", &a, &b);\n printf("Sum: %d\\n", a + b);\n return 0;\n}''',
|
|
@@ -32,8 +34,17 @@ DEFAULT_SNIPPETS = {
|
|
| 32 |
"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}'''
|
| 33 |
}
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
with theme_col:
|
|
|
|
| 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 |
+
# Language dropdown
|
| 19 |
with lang_col:
|
| 20 |
lang = st.selectbox(
|
| 21 |
"Language",
|
|
|
|
| 24 |
key="language"
|
| 25 |
)
|
| 26 |
|
| 27 |
+
# Default code snippets for each language
|
| 28 |
DEFAULT_SNIPPETS = {
|
| 29 |
"Python": '''a = int(input())\nb = int(input())\nprint("Sum:", a + b)''',
|
| 30 |
"C": '''#include <stdio.h>\nint main() {\n int a, b;\n scanf("%d %d", &a, &b);\n printf("Sum: %d\\n", a + b);\n return 0;\n}''',
|
|
|
|
| 34 |
"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}'''
|
| 35 |
}
|
| 36 |
|
| 37 |
+
# Detect language change and reset code if appropriate
|
| 38 |
+
prev_lang = st.session_state.get("prev_language")
|
| 39 |
+
default_code = DEFAULT_SNIPPETS.get(lang, "")
|
| 40 |
+
old_default = DEFAULT_SNIPPETS.get(prev_lang, "") if prev_lang else ""
|
| 41 |
+
|
| 42 |
+
is_editor_empty_or_default = st.session_state.code.strip() in ["", old_default]
|
| 43 |
+
|
| 44 |
+
if lang != prev_lang and is_editor_empty_or_default:
|
| 45 |
+
st.session_state.code = default_code
|
| 46 |
+
|
| 47 |
+
st.session_state.prev_language = lang
|
| 48 |
|
| 49 |
|
| 50 |
with theme_col:
|