Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,17 @@ import gradio as gr
|
|
2 |
from packaging import version
|
3 |
import subprocess, tempfile, os, uuid, resource
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# --- Funci贸n principal --------------------------------------------------------
|
6 |
def compile_and_run(code: str, stdin: str = "") -> str:
|
7 |
"""
|
@@ -71,18 +82,18 @@ Tambi茅n disponible como endpoint REST (`/run/predict`).
|
|
71 |
"""
|
72 |
|
73 |
demo = gr.Interface(
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
)
|
87 |
|
88 |
if __name__ == "__main__":
|
|
|
2 |
from packaging import version
|
3 |
import subprocess, tempfile, os, uuid, resource
|
4 |
|
5 |
+
# ---------- utilidades ----------
|
6 |
+
def _detect_c_language():
|
7 |
+
"""
|
8 |
+
Devuelve 'c' si est谩 en la lista de lenguajes de gr.Code,
|
9 |
+
o 'cpp' como fallback para versiones antiguas (<4.0).
|
10 |
+
"""
|
11 |
+
langs = getattr(gr.Code, "languages", [])
|
12 |
+
return "c" if "c" in langs else "cpp"
|
13 |
+
|
14 |
+
code_lang = _detect_c_language()
|
15 |
+
|
16 |
# --- Funci贸n principal --------------------------------------------------------
|
17 |
def compile_and_run(code: str, stdin: str = "") -> str:
|
18 |
"""
|
|
|
82 |
"""
|
83 |
|
84 |
demo = gr.Interface(
|
85 |
+
fn = compile_and_run,
|
86 |
+
inputs = [
|
87 |
+
gr.Code(language=code_lang, label="C贸digo C"),
|
88 |
+
gr.Textbox(lines=3, placeholder="Entrada est谩ndar (stdin)", label="Stdin (opcional)")
|
89 |
+
],
|
90 |
+
outputs = gr.Textbox(label="Resultado"),
|
91 |
+
title = title,
|
92 |
+
description = description,
|
93 |
+
examples = [
|
94 |
+
[r"#include <stdio.h>\nint main(){printf(\"Hola 42!\\n\");}", ""],
|
95 |
+
[r"#include <stdio.h>\nint main(){int a,b;scanf(\"%d %d\",&a,&b);printf(\"%d\\n\",a+b);}", "3 4"]
|
96 |
+
],
|
97 |
)
|
98 |
|
99 |
if __name__ == "__main__":
|