Spaces:
Sleeping
Sleeping
import streamlit as st | |
st.title("Code Converter") | |
st.divider() | |
input, output = st.columns(2) | |
out = "" | |
def python_to_javascript(python_code): | |
js_code = python_code | |
replacements = { | |
"print": "console.log", | |
"if": "if", | |
"elif": "else if", | |
"else": "else", | |
"True": "true", | |
"False": "false", | |
"==": "===", | |
"and": "&&", | |
"or": "||", | |
"not": "!", | |
"in": "includes", | |
"range": "Array.from(Array", | |
"for": "for", | |
"while": "while", | |
"continue": "continue", | |
"break": "break", | |
"def": "function", | |
"return": "return", | |
"lambda": "() =>", | |
"is": "===", | |
"None": "null", | |
"import": "import", | |
"from": "from", | |
"as": "as", | |
"class": "class", | |
"self": "this", | |
"del": "delete", | |
"try": "try", | |
"except": "catch", | |
"finally": "finally", | |
"raise": "throw", | |
"assert": "assert", | |
"async": "async", | |
"await": "await", | |
"yield": "yield", | |
"global": "global", | |
"nonlocal": "nonlocal", | |
"pass": "pass", | |
"with": "with", | |
"yield from": "yield from", | |
"async for": "for await", | |
"async with": "async with", | |
"async def": "async function" | |
} | |
for key, value in replacements.items(): | |
if key in js_code: | |
js_code = js_code.replace(key, value) | |
return js_code | |
input_code_type = input.selectbox( | |
'Convert from', | |
("Python", "Coming soon") | |
) | |
output_code_type = output.selectox( | |
'Convert to', | |
("JavaScript", "Comnig soon") | |
) | |
input_code = input.text_area("Enter yor code", height=300) | |
output_code = output.code(out, language=output_code_type, line_numbers=True) | |
submit = input.button("Convert") | |
if submit: | |
out = python_to_javascript(input_code) |