File size: 1,043 Bytes
66f8fc1 b4c7402 66f8fc1 329f9c0 b4c7402 329f9c0 66f8fc1 329f9c0 720784d |
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 38 |
import gradio as gr
import subprocess
import tempfile
def compile(source):
# Create a temporary file for the C source code
with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as temp_c_file:
temp_c_file.write(source.encode())
temp_c_file_name = temp_c_file.name
# Create a temporary file for the object file
with tempfile.NamedTemporaryFile(suffix=".o", delete=False) as temp_o_file:
temp_o_file_name = temp_o_file.name
# Compile the C file to an object file
subprocess.run(["cc", "-c", temp_c_file_name, "-o", temp_o_file_name], check=True)
# Read the compiled object file and load the bytes into a bytestring
with open(temp_o_file_name, "rb") as f:
compiled_bytes = f.read()
return compiled_bytes
def predict(source):
bytes = compile(source)
return 1.0
def run():
demo = gr.Interface(
fn=predict,
inputs=gr.Textbox,
outputs=gr.Number,
)
demo.launch(server_name="0.0.0.0", server_port=7860)
run() |