Spaces:
Runtime error
Runtime error
add python function
Browse files
app.py
CHANGED
@@ -14,22 +14,55 @@ def query(payload):
|
|
14 |
return response.json()
|
15 |
|
16 |
|
17 |
-
function_code =
|
18 |
-
|
19 |
-
|
|
|
|
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# payload = json.dumps(inputs)
|
25 |
# prediction = req.request(CT5_METHOD, CT5_URL, data=payload)
|
26 |
# prediction = req.request(CT5_METHOD, CT5_URL, json=req_data)
|
27 |
# answer = json.loads(prediction.content.decode("utf-8"))
|
28 |
-
return
|
29 |
|
30 |
iface = gr.Interface(pygen_func,
|
31 |
[
|
32 |
-
gr.inputs.Textbox(lines=7, label="Code Intent NL", default=
|
33 |
],
|
34 |
gr.outputs.Textbox(label="Code Generated PL"))
|
35 |
iface.launch(share=True)
|
|
|
14 |
return response.json()
|
15 |
|
16 |
|
17 |
+
function_code = r"""
|
18 |
+
def fetch_archive_from_http(url: str, output_dir: str, proxies: Optional[dict] = None) -> bool:
|
19 |
+
path = Path(output_dir)
|
20 |
+
if not path.exists():
|
21 |
+
path.mkdir(parents=True)
|
22 |
|
23 |
+
is_not_empty = len(list(Path(path).rglob("*"))) > 0
|
24 |
+
if is_not_empty:
|
25 |
+
return False
|
26 |
+
else:
|
27 |
+
_, _, archive_extension = url.rpartition(".")
|
28 |
+
request_data = requests.get(url, proxies=proxies)
|
29 |
|
30 |
+
if archive_extension == "zip":
|
31 |
+
zip_archive = zipfile.ZipFile(io.BytesIO(request_data.content))
|
32 |
+
zip_archive.extractall(output_dir)
|
33 |
+
elif archive_extension in ["gz", "bz2", "xz"]:
|
34 |
+
tar_archive = tarfile.open(fileobj=io.BytesIO(request_data.content), mode="r|*")
|
35 |
+
tar_archive.extractall(output_dir)
|
36 |
+
else:
|
37 |
+
pass
|
38 |
+
|
39 |
+
return True
|
40 |
+
"""
|
41 |
+
|
42 |
+
real_docstring = r"""
|
43 |
+
Fetch an archive (zip or tar.gz) from a url via http and extract content to an output directory.
|
44 |
+
|
45 |
+
:param url: http address
|
46 |
+
:param output_dir: local path
|
47 |
+
:param proxies: proxies details as required by requests library
|
48 |
+
:return: if anything got fetched
|
49 |
+
"""
|
50 |
+
|
51 |
+
def pygen_func(function_code):
|
52 |
+
req_data = {"inputs": function_code}
|
53 |
+
output = query(req_data)
|
54 |
+
return str(output)
|
55 |
+
|
56 |
+
# inputs = {'code_nl': code_nl}
|
57 |
# payload = json.dumps(inputs)
|
58 |
# prediction = req.request(CT5_METHOD, CT5_URL, data=payload)
|
59 |
# prediction = req.request(CT5_METHOD, CT5_URL, json=req_data)
|
60 |
# answer = json.loads(prediction.content.decode("utf-8"))
|
61 |
+
# return str(answer)
|
62 |
|
63 |
iface = gr.Interface(pygen_func,
|
64 |
[
|
65 |
+
gr.inputs.Textbox(lines=7, label="Code Intent NL", default=function_code),
|
66 |
],
|
67 |
gr.outputs.Textbox(label="Code Generated PL"))
|
68 |
iface.launch(share=True)
|