Spaces:
Runtime error
Runtime error
Allow users to specify citation style
Browse files- app.py +13 -1
- functions.py +3 -3
app.py
CHANGED
@@ -53,6 +53,11 @@ with gr.Blocks(css=css_style) as demo:
|
|
53 |
"User", "Group"], label="Zotero Library Type", value="User", elem_id="zotero-library-type")
|
54 |
zot_library_id = gr.Textbox(
|
55 |
label="Zotero User/Group ID", value=os.getenv('ZOTERO_LIBRARY_ID'))
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
zot_selected_col = gr.Radio(
|
58 |
[], label="Zotero Collection", elem_id="zotero-collection", visible=False)
|
@@ -108,6 +113,13 @@ with gr.Blocks(css=css_style) as demo:
|
|
108 |
question, answer, messages, msg_board, zot_selected_col],
|
109 |
show_progress=False
|
110 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
zot_fetch_col_btn.click(
|
113 |
fn=fetch_collections,
|
@@ -126,7 +138,7 @@ with gr.Blocks(css=css_style) as demo:
|
|
126 |
|
127 |
question.submit(
|
128 |
fn=handle_submit,
|
129 |
-
inputs=[zot, zot_selected_col, zot_collections, question, messages],
|
130 |
outputs=[messages, msg_board, answer],
|
131 |
show_progress=False
|
132 |
)
|
|
|
53 |
"User", "Group"], label="Zotero Library Type", value="User", elem_id="zotero-library-type")
|
54 |
zot_library_id = gr.Textbox(
|
55 |
label="Zotero User/Group ID", value=os.getenv('ZOTERO_LIBRARY_ID'))
|
56 |
+
|
57 |
+
zot_citation_style = gr.Textbox(
|
58 |
+
label="Zotero Citation Style",
|
59 |
+
value='nature',
|
60 |
+
)
|
61 |
|
62 |
zot_selected_col = gr.Radio(
|
63 |
[], label="Zotero Collection", elem_id="zotero-collection", visible=False)
|
|
|
113 |
question, answer, messages, msg_board, zot_selected_col],
|
114 |
show_progress=False
|
115 |
)
|
116 |
+
zot_citation_style.change(
|
117 |
+
reset_collection,
|
118 |
+
inputs=[messages],
|
119 |
+
outputs=[zot_selected_col, zot_fetch_col_btn,
|
120 |
+
question, answer, messages, msg_board, zot_selected_col],
|
121 |
+
show_progress=False
|
122 |
+
)
|
123 |
|
124 |
zot_fetch_col_btn.click(
|
125 |
fn=fetch_collections,
|
|
|
138 |
|
139 |
question.submit(
|
140 |
fn=handle_submit,
|
141 |
+
inputs=[zot, zot_selected_col, zot_collections, zot_citation_style, question, messages],
|
142 |
outputs=[messages, msg_board, answer],
|
143 |
show_progress=False
|
144 |
)
|
functions.py
CHANGED
@@ -161,7 +161,7 @@ def reset_collection(messages):
|
|
161 |
)
|
162 |
|
163 |
|
164 |
-
def handle_submit(zot, collection_name, collections, question, messages):
|
165 |
collection_name_only = re.sub('\s\(\d+\)$', '', collection_name)
|
166 |
messages.set([Message(
|
167 |
Icons.OK, f"Selected collection: <span style='font-weight: bold'>{collection_name_only}</span>.")])
|
@@ -257,9 +257,9 @@ def handle_submit(zot, collection_name, collections, question, messages):
|
|
257 |
citation_dict[attachment["key"]] = parents[parent_id]
|
258 |
else:
|
259 |
parent = zot.item(
|
260 |
-
parent_id, content="bib", style=
|
261 |
bib = f"""
|
262 |
-
{html.fragment_fromstring(parent).xpath("normalize-space(
|
263 |
<a href="{attachment['links']['alternate']['href']}" target="_blank" class="zotero-link">Open in Zotero</a>
|
264 |
"""
|
265 |
parents[parent_id] = bib
|
|
|
161 |
)
|
162 |
|
163 |
|
164 |
+
def handle_submit(zot, collection_name, collections, style, question, messages):
|
165 |
collection_name_only = re.sub('\s\(\d+\)$', '', collection_name)
|
166 |
messages.set([Message(
|
167 |
Icons.OK, f"Selected collection: <span style='font-weight: bold'>{collection_name_only}</span>.")])
|
|
|
257 |
citation_dict[attachment["key"]] = parents[parent_id]
|
258 |
else:
|
259 |
parent = zot.item(
|
260 |
+
parent_id, content="bib", style=style)[0]
|
261 |
bib = f"""
|
262 |
+
{html.fragment_fromstring(parent).xpath("normalize-space(//*)")}
|
263 |
<a href="{attachment['links']['alternate']['href']}" target="_blank" class="zotero-link">Open in Zotero</a>
|
264 |
"""
|
265 |
parents[parent_id] = bib
|