Spaces:
Sleeping
Sleeping
Added default snippet
Browse files
app.py
CHANGED
|
@@ -12,8 +12,7 @@ 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,6 +21,20 @@ with lang_col:
|
|
| 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 == "🌙")
|
|
|
|
| 12 |
st.title("Pro Code Playground")
|
| 13 |
st.markdown("Write, execute & export multi-language snippets, with built‑in AI assistance.")
|
| 14 |
|
| 15 |
+
# Language selector
|
|
|
|
| 16 |
with lang_col:
|
| 17 |
lang = st.selectbox(
|
| 18 |
"Language",
|
|
|
|
| 21 |
key="language"
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Load default code if editor is empty
|
| 25 |
+
DEFAULT_SNIPPETS = {
|
| 26 |
+
"Python": '''a = int(input())\nb = int(input())\nprint("Sum:", a + b)''',
|
| 27 |
+
"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}''',
|
| 28 |
+
"C++": '''#include <iostream>\nusing namespace std;\nint main() {\n int a, b;\n cin >> a >> b;\n cout << "Sum: " << a + b << endl;\n return 0;\n}''',
|
| 29 |
+
"Java": '''import java.util.Scanner;\npublic class Program {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n System.out.println("Sum: " + (a + b));\n }\n}''',
|
| 30 |
+
"JavaScript": '''const readline = require('readline');\nconst rl = readline.createInterface({ input: process.stdin, output: process.stdout });\nlet inputs = [];\nrl.on('line', (line) => {\n inputs.push(parseInt(line));\n if (inputs.length === 2) {\n console.log("Sum:", inputs[0] + inputs[1]);\n rl.close();\n }\n});''',
|
| 31 |
+
"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}'''
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
if st.session_state.code.strip() == "":
|
| 35 |
+
st.session_state.code = DEFAULT_SNIPPETS.get(lang, "")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
with theme_col:
|
| 39 |
theme_choice = st.radio("Theme", options=["☀️", "🌙"], horizontal=True, label_visibility="collapsed")
|
| 40 |
st.session_state.dark_mode = (theme_choice == "🌙")
|