add step 1
Browse files- .gitignore +2 -0
- app.py +33 -4
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flagged/
|
| 2 |
+
__pycache__/
|
app.py
CHANGED
|
@@ -13,6 +13,7 @@ t2 = torch.arange({n2}).view({dim2})
|
|
| 13 |
(t1 @ t2).shape = {out_shape}
|
| 14 |
|
| 15 |
```
|
|
|
|
| 16 |
"""
|
| 17 |
|
| 18 |
|
|
@@ -52,25 +53,53 @@ def sanitize_dimention(dim):
|
|
| 52 |
)
|
| 53 |
return out
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
def predict(dim1, dim2):
|
| 57 |
dim1 = sanitize_dimention(dim1)
|
| 58 |
dim2 = sanitize_dimention(dim2)
|
| 59 |
n1,dim1,n2,dim2,out_shape = generate_example(dim1, dim2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# TODO
|
| 62 |
# add code exmplanation here
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
)
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
demo = gr.Interface(
|
| 70 |
predict,
|
| 71 |
inputs=["text", "text"],
|
| 72 |
outputs=["markdown"],
|
| 73 |
-
examples=[["1,2,3", "5,3,7"], ["1,2,3", "5,2,7"]],
|
| 74 |
)
|
| 75 |
|
| 76 |
demo.launch(debug=True)
|
|
|
|
| 13 |
(t1 @ t2).shape = {out_shape}
|
| 14 |
|
| 15 |
```
|
| 16 |
+
|
| 17 |
"""
|
| 18 |
|
| 19 |
|
|
|
|
| 53 |
)
|
| 54 |
return out
|
| 55 |
|
| 56 |
+
def generate_table(n1,dim1,n2,dim2,out_shape,n_dim):
|
| 57 |
+
makdown_table = ""
|
| 58 |
+
makdown_table += "| <!-- --> "*n_dim + "|\n" # header
|
| 59 |
+
makdown_table += "|---"*n_dim + "|\n" # line
|
| 60 |
+
|
| 61 |
+
# tensor 1
|
| 62 |
+
for index in range(n_dim):
|
| 63 |
+
if index < (n_dim - n1):
|
| 64 |
+
makdown_table += "| "
|
| 65 |
+
else:
|
| 66 |
+
makdown_table += f"| {dim1[index - (n_dim- n2)]}"
|
| 67 |
+
makdown_table +="|\n"
|
| 68 |
+
# tensor 2
|
| 69 |
+
for index in range(n_dim):
|
| 70 |
+
if index < (n_dim - n2):
|
| 71 |
+
makdown_table += "| "
|
| 72 |
+
else:
|
| 73 |
+
makdown_table += f"| {dim2[index - (n_dim- n2)]}"
|
| 74 |
+
makdown_table +="|\n"
|
| 75 |
+
return makdown_table
|
| 76 |
|
| 77 |
def predict(dim1, dim2):
|
| 78 |
dim1 = sanitize_dimention(dim1)
|
| 79 |
dim2 = sanitize_dimention(dim2)
|
| 80 |
n1,dim1,n2,dim2,out_shape = generate_example(dim1, dim2)
|
| 81 |
+
code = EXAMPLE_MD.format(
|
| 82 |
+
n1=str(n1), dim1=str(dim1), n2=str(n2), dim2=str(dim2), out_shape=str(out_shape)
|
| 83 |
+
)
|
| 84 |
+
n1 = len(dim1)
|
| 85 |
+
n2 = len(dim2)
|
| 86 |
+
n_dim = max(n1,n2)
|
| 87 |
+
table1 = generate_table(n1,dim1,n2,dim2,out_shape,n_dim)
|
| 88 |
|
| 89 |
# TODO
|
| 90 |
# add code exmplanation here
|
| 91 |
|
| 92 |
+
|
| 93 |
+
out = code
|
| 94 |
+
out+= "\n# Step1 (alignment)" + "\n" + table1
|
| 95 |
+
return out
|
| 96 |
|
| 97 |
|
| 98 |
demo = gr.Interface(
|
| 99 |
predict,
|
| 100 |
inputs=["text", "text"],
|
| 101 |
outputs=["markdown"],
|
| 102 |
+
examples=[["1,2,3,3,3", "5,3,7"], ["1,2,3", "5,2,7"]],
|
| 103 |
)
|
| 104 |
|
| 105 |
demo.launch(debug=True)
|