|
import gradio as gr |
|
import subprocess |
|
import tempfile |
|
|
|
def compile(source): |
|
|
|
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 |
|
|
|
|
|
with tempfile.NamedTemporaryFile(suffix=".o", delete=False) as temp_o_file: |
|
temp_o_file_name = temp_o_file.name |
|
|
|
|
|
subprocess.run(["cc", "-c", temp_c_file_name, "-o", temp_o_file_name], check=True) |
|
|
|
|
|
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) |
|
|