Spaces:
Runtime error
Runtime error
Commit
·
8e9c357
1
Parent(s):
2636ace
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,8 @@ import psycopg2
|
|
| 9 |
conn = psycopg2.connect("CONN")
|
| 10 |
cur = conn.cursor()
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
# PROMPT
|
| 14 |
cur.execute("UPDATE customer SET name
|
| 15 |
"""
|
|
@@ -42,7 +43,7 @@ def generation(tokenizer, model, content):
|
|
| 42 |
txt = tokenizer.decode(typ_output[0], skip_special_tokens=True)
|
| 43 |
return txt
|
| 44 |
|
| 45 |
-
def code_from_prompts(prompt, model, type_hints):
|
| 46 |
tokenizer = AutoTokenizer.from_pretrained(modelPath[model])
|
| 47 |
model = AutoModelForCausalLM.from_pretrained(modelPath[model])
|
| 48 |
|
|
@@ -50,8 +51,24 @@ def code_from_prompts(prompt, model, type_hints):
|
|
| 50 |
|
| 51 |
if type_hints:
|
| 52 |
code = code.replace('id,', 'id: int,')
|
|
|
|
| 53 |
code = code.replace('new_name)', 'new_name: str) -> None')
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
results = [
|
| 56 |
generation(tokenizer, model, code),
|
| 57 |
0.5,
|
|
@@ -65,7 +82,12 @@ iface = gr.Interface(
|
|
| 65 |
inputs=[
|
| 66 |
gr.inputs.Textbox(label="Insert comment"),
|
| 67 |
gr.inputs.Radio(list(modelPath.keys()), label="Code Model"),
|
| 68 |
-
gr.inputs.Checkbox(label="Include type hints")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
],
|
| 70 |
outputs=[
|
| 71 |
gr.outputs.Textbox(label="Generated code"),
|
|
|
|
| 9 |
conn = psycopg2.connect("CONN")
|
| 10 |
cur = conn.cursor()
|
| 11 |
|
| 12 |
+
MIDDLE
|
| 13 |
+
def rename_customer(id, new_name):
|
| 14 |
# PROMPT
|
| 15 |
cur.execute("UPDATE customer SET name
|
| 16 |
"""
|
|
|
|
| 43 |
txt = tokenizer.decode(typ_output[0], skip_special_tokens=True)
|
| 44 |
return txt
|
| 45 |
|
| 46 |
+
def code_from_prompts(prompt, model, type_hints, pre_content):
|
| 47 |
tokenizer = AutoTokenizer.from_pretrained(modelPath[model])
|
| 48 |
model = AutoModelForCausalLM.from_pretrained(modelPath[model])
|
| 49 |
|
|
|
|
| 51 |
|
| 52 |
if type_hints:
|
| 53 |
code = code.replace('id,', 'id: int,')
|
| 54 |
+
code = code.replace('id)', 'id: int)')
|
| 55 |
code = code.replace('new_name)', 'new_name: str) -> None')
|
| 56 |
|
| 57 |
+
if pre_content == 'None':
|
| 58 |
+
code = code.replace('MIDDLE\n', '')
|
| 59 |
+
elif 'Concatenation' in pre_content:
|
| 60 |
+
code = code.replace('MIDDLE', """
|
| 61 |
+
def get_customer(id):
|
| 62 |
+
cur.execute('SELECT * FROM customers WHERE id = ' + str(id))
|
| 63 |
+
return cur.fetchall()
|
| 64 |
+
""".strip())
|
| 65 |
+
elif 'composition' in pre_content:
|
| 66 |
+
code = code.replace('MIDDLE', """
|
| 67 |
+
def get_customer(id):
|
| 68 |
+
cur.execute('SELECT * FROM customers WHERE id = %s', str(id))
|
| 69 |
+
return cur.fetchall()
|
| 70 |
+
""".strip())
|
| 71 |
+
|
| 72 |
results = [
|
| 73 |
generation(tokenizer, model, code),
|
| 74 |
0.5,
|
|
|
|
| 82 |
inputs=[
|
| 83 |
gr.inputs.Textbox(label="Insert comment"),
|
| 84 |
gr.inputs.Radio(list(modelPath.keys()), label="Code Model"),
|
| 85 |
+
gr.inputs.Checkbox(label="Include type hints"),
|
| 86 |
+
gr.inputs.Radio([
|
| 87 |
+
"None",
|
| 88 |
+
"Proper composition: Include function 'WHERE id = %s'",
|
| 89 |
+
"Concatenation: Include a function with 'WHERE id = ' + id",
|
| 90 |
+
], label="Pre-written function")
|
| 91 |
],
|
| 92 |
outputs=[
|
| 93 |
gr.outputs.Textbox(label="Generated code"),
|