Spaces:
Sleeping
Sleeping
Commit
·
b4c7402
1
Parent(s):
7cbd81a
compilation
Browse files- main.py +27 -20
- requirements.txt +0 -1
main.py
CHANGED
@@ -1,30 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
with
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
def run():
|
20 |
demo = gr.Interface(
|
21 |
fn=predict,
|
22 |
-
inputs=gr.
|
23 |
-
outputs=gr.
|
24 |
)
|
25 |
|
26 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
27 |
-
|
28 |
-
|
29 |
-
if __name__ == "__main__":
|
30 |
-
run()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
import subprocess
|
4 |
+
import tempfile
|
5 |
+
|
6 |
+
def compile(source):
|
7 |
+
# Create a temporary file for the C source code
|
8 |
+
with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as temp_c_file:
|
9 |
+
temp_c_file.write(source.encode())
|
10 |
+
temp_c_file_name = temp_c_file.name
|
11 |
+
|
12 |
+
# Create a temporary file for the object file
|
13 |
+
with tempfile.NamedTemporaryFile(suffix=".o", delete=False) as temp_o_file:
|
14 |
+
temp_o_file_name = temp_o_file.name
|
15 |
+
|
16 |
+
# Compile the C file to an object file
|
17 |
+
subprocess.run(["cc", "-c", temp_c_file_name, "-o", temp_o_file_name], check=True)
|
18 |
+
|
19 |
+
# Read the compiled object file and load the bytes into a bytestring
|
20 |
+
with open(temp_o_file_name, "rb") as f:
|
21 |
+
compiled_bytes = f.read()
|
22 |
+
|
23 |
+
return compiled_bytes
|
24 |
+
|
25 |
+
def predict(source):
|
26 |
+
bytes = compile(source)
|
27 |
+
return 1.0
|
28 |
|
29 |
|
30 |
def run():
|
31 |
demo = gr.Interface(
|
32 |
fn=predict,
|
33 |
+
inputs=gr.Textbox,
|
34 |
+
outputs=gr.Number,
|
35 |
)
|
36 |
|
37 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
gradio
|
2 |
torch
|
3 |
-
torchvision
|
4 |
requests
|
|
|
1 |
gradio
|
2 |
torch
|
|
|
3 |
requests
|