File size: 1,027 Bytes
9543229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a573faa
 
9543229
 
 
 
 
 
 
 
 
 
 
 
8ac1820
9543229
 
8502c00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)