Spaces:
Runtime error
Runtime error
Ramesh-vani
commited on
Commit
•
549ea36
1
Parent(s):
8251080
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
import gradio
|
2 |
import subprocess
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def run_command(command):
|
6 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
@@ -32,14 +38,18 @@ def run_code(command):
|
|
32 |
except subprocess.CalledProcessError as e:
|
33 |
result = str(e)
|
34 |
elif lang == 'java':
|
|
|
35 |
try:
|
36 |
-
|
|
|
37 |
f.write(code)
|
38 |
-
compile_command = f"javac
|
39 |
compile_process = subprocess.Popen(compile_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
40 |
compile_output, compile_error = compile_process.communicate()
|
41 |
-
if
|
42 |
-
|
|
|
|
|
43 |
run_process = subprocess.Popen(run_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
44 |
run_output, run_error = run_process.communicate()
|
45 |
if run_process.returncode == 0:
|
|
|
1 |
import gradio
|
2 |
import subprocess
|
3 |
+
import re
|
4 |
|
5 |
+
def extract_class_name(java_code):
|
6 |
+
match = re.search(r'class\s+(\w+)\s*\{', java_code)
|
7 |
+
if match:
|
8 |
+
return match.group(1)
|
9 |
+
return None
|
10 |
|
11 |
def run_command(command):
|
12 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
38 |
except subprocess.CalledProcessError as e:
|
39 |
result = str(e)
|
40 |
elif lang == 'java':
|
41 |
+
class_name = extract_class_name(code)
|
42 |
try:
|
43 |
+
|
44 |
+
with open(f'{class_name}.java', 'w') as f:
|
45 |
f.write(code)
|
46 |
+
compile_command = f"javac {class_name}.java"
|
47 |
compile_process = subprocess.Popen(compile_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
48 |
compile_output, compile_error = compile_process.communicate()
|
49 |
+
if not class_name:
|
50 |
+
result ='Unable to extract class name from code'
|
51 |
+
elif compile_process.returncode == 0:
|
52 |
+
run_command = f"java {class_name}"
|
53 |
run_process = subprocess.Popen(run_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
54 |
run_output, run_error = run_process.communicate()
|
55 |
if run_process.returncode == 0:
|