Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.title("Code Converter")
|
| 4 |
+
st.divider
|
| 5 |
+
input, output = st.columns(2)
|
| 6 |
+
out = ""
|
| 7 |
+
|
| 8 |
+
def python_to_javascript(python_code):
|
| 9 |
+
js_code = python_code
|
| 10 |
+
replacements = {
|
| 11 |
+
"print": "console.log",
|
| 12 |
+
"if": "if",
|
| 13 |
+
"elif": "else if",
|
| 14 |
+
"else": "else",
|
| 15 |
+
"True": "true",
|
| 16 |
+
"False": "false",
|
| 17 |
+
"==": "===",
|
| 18 |
+
"and": "&&",
|
| 19 |
+
"or": "||",
|
| 20 |
+
"not": "!",
|
| 21 |
+
"in": "includes",
|
| 22 |
+
"range": "Array.from(Array",
|
| 23 |
+
"for": "for",
|
| 24 |
+
"while": "while",
|
| 25 |
+
"continue": "continue",
|
| 26 |
+
"break": "break",
|
| 27 |
+
"def": "function",
|
| 28 |
+
"return": "return",
|
| 29 |
+
"lambda": "() =>",
|
| 30 |
+
"is": "===",
|
| 31 |
+
"None": "null",
|
| 32 |
+
"import": "import",
|
| 33 |
+
"from": "from",
|
| 34 |
+
"as": "as",
|
| 35 |
+
"class": "class",
|
| 36 |
+
"self": "this",
|
| 37 |
+
"del": "delete",
|
| 38 |
+
"try": "try",
|
| 39 |
+
"except": "catch",
|
| 40 |
+
"finally": "finally",
|
| 41 |
+
"raise": "throw",
|
| 42 |
+
"assert": "assert",
|
| 43 |
+
"async": "async",
|
| 44 |
+
"await": "await",
|
| 45 |
+
"yield": "yield",
|
| 46 |
+
"global": "global",
|
| 47 |
+
"nonlocal": "nonlocal",
|
| 48 |
+
"pass": "pass",
|
| 49 |
+
"with": "with",
|
| 50 |
+
"yield from": "yield from",
|
| 51 |
+
"async for": "for await",
|
| 52 |
+
"async with": "async with",
|
| 53 |
+
"async def": "async function"
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
for key, value in replacements.items():
|
| 57 |
+
if key in js_code:
|
| 58 |
+
js_code = js_code.replace(key, value)
|
| 59 |
+
|
| 60 |
+
return js_code
|
| 61 |
+
|
| 62 |
+
input_code_type = input.selectbox(
|
| 63 |
+
'Convert from'
|
| 64 |
+
("Python", "Coming soon")
|
| 65 |
+
)
|
| 66 |
+
output_code_type = output.selectob(
|
| 67 |
+
'Convert to'
|
| 68 |
+
("JavaScript", "Comnig soon")
|
| 69 |
+
)
|
| 70 |
+
input_code = input.text_area("Enter yor code", height=300)
|
| 71 |
+
output_code = output.code(out, language=output_code_type, line_numbers=True)
|
| 72 |
+
submit = input.button("Convert")
|
| 73 |
+
if submit:
|
| 74 |
+
out = python_to_javascript(input_code)
|