Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import subprocess | |
| def run_java(input_value, output_file): | |
| # Run the Java program using subprocess and redirect input/output | |
| subprocess.run(["java", "YourJavaProgram", input_value]) | |
| # Read the content of the output file | |
| with open(output_file, "r") as file: | |
| result = file.read() | |
| return result | |
| def java_program_runner(input_file): | |
| output_file = "output.txt" | |
| with open(input_file, "r") as file: | |
| input_value = file.read() | |
| print(input_value) | |
| run_java(input_value, output_file) | |
| # if output.txt is not created, create first | |
| with open(output_file, "r") as file: | |
| result = file.read() | |
| print(result) | |
| return result | |
| iface = gr.Interface( | |
| fn=java_program_runner, | |
| inputs=gr.File(label="Input File"), | |
| outputs="text", | |
| title="Java Program Runner", | |
| description="Runs a Java program and returns the result.", | |
| theme="default", | |
| allow_flagging="never", | |
| ) | |
| iface.launch(server_name="0.0.0.0", server_port=7860) |