Spaces:
Runtime error
Runtime error
Sean MacAvaney
commited on
Commit
·
cba50c7
1
Parent(s):
d941d78
update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,52 @@ from pyterrier_doc2query import Doc2Query
|
|
3 |
|
4 |
doc2query = Doc2Query()
|
5 |
|
6 |
-
def
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
gr.Interface(
|
10 |
predict,
|
11 |
-
inputs=gr.Dataframe(
|
12 |
headers=["docno", "text"],
|
13 |
datatype=["str", "str"],
|
14 |
col_count=(2, "fixed"),
|
|
|
|
|
|
|
15 |
value=[['0', 'The presence of communication amid scientific minds was equally important to the success of the Manhattan Project as scientific intellect was. The only cloud hanging over the impressive achievement of the atomic researchers and engineers is what their success truly meant; hundreds of thousands of innocent lives obliterated.']],
|
16 |
-
),
|
17 |
-
|
|
|
|
|
|
|
18 |
headers=["docno", "text", "querygen"],
|
19 |
datatype=["str", "str", "str"],
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
).launch()
|
|
|
3 |
|
4 |
doc2query = Doc2Query()
|
5 |
|
6 |
+
def df2code(df):
|
7 |
+
rows = []
|
8 |
+
for row in df.itertuples(index=False):
|
9 |
+
rows.append(f' {dict(row._asdict())},')
|
10 |
+
rows = '\n'.join(rows)
|
11 |
+
return f'''pd.DataFrame([
|
12 |
+
{rows}
|
13 |
+
])'''
|
14 |
+
|
15 |
+
def predict(input, append):
|
16 |
+
doc2query.append = append
|
17 |
+
code = f'''
|
18 |
+
## Code:
|
19 |
+
|
20 |
+
```python
|
21 |
+
import pandas as pd
|
22 |
+
from pyterrier_doc2query import Doc2Query
|
23 |
+
doc2query = Doc2Query(append={append})
|
24 |
+
doc2query({df2code(input)})
|
25 |
+
```
|
26 |
+
'''
|
27 |
+
return (doc2query(input), code)
|
28 |
|
29 |
gr.Interface(
|
30 |
predict,
|
31 |
+
inputs=[gr.Dataframe(
|
32 |
headers=["docno", "text"],
|
33 |
datatype=["str", "str"],
|
34 |
col_count=(2, "fixed"),
|
35 |
+
row_count=1,
|
36 |
+
wrap=True,
|
37 |
+
label='Pipeline Input',
|
38 |
value=[['0', 'The presence of communication amid scientific minds was equally important to the success of the Manhattan Project as scientific intellect was. The only cloud hanging over the impressive achievement of the atomic researchers and engineers is what their success truly meant; hundreds of thousands of innocent lives obliterated.']],
|
39 |
+
), gr.Checkbox(
|
40 |
+
value=False,
|
41 |
+
label="Append",
|
42 |
+
)],
|
43 |
+
outputs=[gr.Dataframe(
|
44 |
headers=["docno", "text", "querygen"],
|
45 |
datatype=["str", "str", "str"],
|
46 |
+
col_count=(3, "fixed"),
|
47 |
+
row_count=1,
|
48 |
+
wrap=True,
|
49 |
+
label='Pipeline Output',
|
50 |
+
value=[["[docno]", "[text]", "[querygen]"]],
|
51 |
+
), gr.Markdown()],
|
52 |
+
title="PyTerrier: Doc2Query",
|
53 |
+
allow_flagging=False,
|
54 |
).launch()
|