File size: 765 Bytes
4f40f5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr  
import subprocess  
import os  

UPLOAD_FOLDER = "uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

def execute_exe(file):  
    file_path = os.path.join(UPLOAD_FOLDER, file.name)  
    file.save(file_path)  

    try:  
        result = subprocess.run(["bash", "run_exe.sh", file_path], capture_output=True, text=True, timeout=10)  
        return result.stdout if result.stdout else "No output."  
    except subprocess.TimeoutExpired:  
        return "Execution timed out."

with gr.Blocks() as app:  
    gr.Markdown("### Upload an EXE file to execute")  
    file_input = gr.File(label="Upload EXE")  
    output_text = gr.Textbox(label="Execution Output")  
    file_input.change(execute_exe, file_input, output_text)  

app.launch()