Spaces:
Sleeping
Sleeping
Adding file formate with downloading
Browse files- code_editor.py +18 -1
code_editor.py
CHANGED
|
@@ -103,4 +103,21 @@ def render_code_editor(selected_lang, ace_theme, editor_key):
|
|
| 103 |
st.markdown(f"💾 **Memory Used:** `{mem_used:.2f} KB`")
|
| 104 |
|
| 105 |
if st.session_state.code:
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
st.markdown(f"💾 **Memory Used:** `{mem_used:.2f} KB`")
|
| 104 |
|
| 105 |
if st.session_state.code:
|
| 106 |
+
# Map Streamlit language to proper file extensions
|
| 107 |
+
lang_extension = {
|
| 108 |
+
"Python": "py",
|
| 109 |
+
"C": "c",
|
| 110 |
+
"C++": "cpp",
|
| 111 |
+
"Java": "java",
|
| 112 |
+
"JavaScript": "js",
|
| 113 |
+
"C#": "cs"
|
| 114 |
+
}
|
| 115 |
+
ext = lang_extension.get(selected_lang, "txt")
|
| 116 |
+
|
| 117 |
+
st.download_button(
|
| 118 |
+
label="💾 Download Code",
|
| 119 |
+
data=st.session_state.code,
|
| 120 |
+
file_name=f"code.{ext}",
|
| 121 |
+
mime="text/plain"
|
| 122 |
+
)
|
| 123 |
+
|