Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import
|
| 3 |
-
import requests as req
|
| 4 |
|
| 5 |
code_nl = "function for db connection"
|
| 6 |
|
|
@@ -13,16 +12,6 @@ def query(payload):
|
|
| 13 |
response = req.post(API_URL, headers=headers, json=payload)
|
| 14 |
return response.json()
|
| 15 |
|
| 16 |
-
|
| 17 |
-
dfs_code = r"""
|
| 18 |
-
def dfs(visited, graph, node): #function for dfs
|
| 19 |
-
if node not in visited:
|
| 20 |
-
print (node)
|
| 21 |
-
visited.add(node)
|
| 22 |
-
for neighbour in graph[node]:
|
| 23 |
-
dfs(visited, graph, neighbour)
|
| 24 |
-
"""
|
| 25 |
-
|
| 26 |
function_code = r"""
|
| 27 |
def write_documents(self, documents: Union[List[dict], List[Document]], index: Optional[str] = None,
|
| 28 |
batch_size: int = 10_000, duplicate_documents: Optional[str] = None):
|
|
@@ -192,6 +181,14 @@ def docgen_func(function_code, min_length, max_length, top_k, top_p, temp, repet
|
|
| 192 |
return msg + 'Please wait for the model to load and try again'
|
| 193 |
return str(output)
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
iface = gr.Interface(
|
| 196 |
# pygen_func,
|
| 197 |
docgen_func,
|
|
@@ -209,18 +206,13 @@ iface = gr.Interface(
|
|
| 209 |
gr.outputs.Textbox(label="Docstring Generated (Natural Language, code comment for documentation)"),
|
| 210 |
layout="unaligned",
|
| 211 |
title='Generate a documentation string for Python code',
|
| 212 |
-
description=
|
| 213 |
-
article=
|
| 214 |
-
|
| 215 |
-
_A model is given the task to generate natural language comments for a programming language code input._
|
| 216 |
-
|
| 217 |
-
For further details, see the [CodeXGLUE](https://github.com/microsoft/CodeXGLUE) benchmark dataset and open challenge for code intelligence.
|
| 218 |
-
""",
|
| 219 |
theme='grass',
|
| 220 |
examples=[[tree_code,50,200,2,70,10,80],[insert_code,100,250,3,90,20,90],[display_code,150,300,5,100,100,95]],
|
| 221 |
verbose=True,
|
| 222 |
# show_tips=True
|
| 223 |
)
|
| 224 |
|
| 225 |
-
iface.launch(share=True)
|
| 226 |
-
|
|
|
|
| 1 |
+
import json; import gradio as gr; import requests as req
|
| 2 |
+
from fun_strings import dfs_code, function_code, real_docstring, tree_code, insert_code, display_code, article_string, descr_string
|
|
|
|
| 3 |
|
| 4 |
code_nl = "function for db connection"
|
| 5 |
|
|
|
|
| 12 |
response = req.post(API_URL, headers=headers, json=payload)
|
| 13 |
return response.json()
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
function_code = r"""
|
| 16 |
def write_documents(self, documents: Union[List[dict], List[Document]], index: Optional[str] = None,
|
| 17 |
batch_size: int = 10_000, duplicate_documents: Optional[str] = None):
|
|
|
|
| 181 |
return msg + 'Please wait for the model to load and try again'
|
| 182 |
return str(output)
|
| 183 |
|
| 184 |
+
article_string = r"""CodeXGLLUE task definition (and dataset): **Code summarization (CodeSearchNet)**:
|
| 185 |
+
|
| 186 |
+
_A model is given the task to generate natural language comments for a programming language code input._
|
| 187 |
+
|
| 188 |
+
For further details, see the [CodeXGLUE](https://github.com/microsoft/CodeXGLUE) benchmark dataset and open challenge for code intelligence.
|
| 189 |
+
"""
|
| 190 |
+
descr_string = 'The application takes as input the python code for a function, or a class, and generates a documentation string, or code comment, for it using codeT5 fine tuned for code2text generation. Code to text generation, or code summarization, is a CodeXGLUE generation, or sequence to sequence, downstream task. CodeXGLUE stands for General Language Understanding Evaluation benchmark *for code*, which includes diversified code intelligence downstream inference tasks and datasets.'
|
| 191 |
+
|
| 192 |
iface = gr.Interface(
|
| 193 |
# pygen_func,
|
| 194 |
docgen_func,
|
|
|
|
| 206 |
gr.outputs.Textbox(label="Docstring Generated (Natural Language, code comment for documentation)"),
|
| 207 |
layout="unaligned",
|
| 208 |
title='Generate a documentation string for Python code',
|
| 209 |
+
description=descr_string,
|
| 210 |
+
article=article_string,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
theme='grass',
|
| 212 |
examples=[[tree_code,50,200,2,70,10,80],[insert_code,100,250,3,90,20,90],[display_code,150,300,5,100,100,95]],
|
| 213 |
verbose=True,
|
| 214 |
# show_tips=True
|
| 215 |
)
|
| 216 |
|
| 217 |
+
# iface.launch(share=True) # "share" not allowed in hf spaces? (!?!?)
|
| 218 |
+
iface.launch()
|