Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,7 +121,7 @@ def create_bibtex_entry(data):
|
|
121 |
|
122 |
#Pages conformity.
|
123 |
if 'pages' in data:
|
124 |
-
match = re.search(r'
|
125 |
if match:
|
126 |
data['pages'] = match.group(1)
|
127 |
else:
|
@@ -201,62 +201,18 @@ class CombinedProcessor:
|
|
201 |
# Create the processor instance
|
202 |
processor = CombinedProcessor()
|
203 |
|
204 |
-
#Gradio interface
|
205 |
with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
206 |
-
gr.HTML("""<h1 style="text-align:center">Reversed Zotero</h1>""")
|
207 |
text_input = gr.Textbox(label="Your text", type="text", lines=10)
|
208 |
text_button = gr.Button("Process Text")
|
|
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
export_button = gr.Button("Export", size="sm")
|
213 |
-
|
214 |
-
file_output = gr.File(label="BibTeX File", visible=False)
|
215 |
|
216 |
text_button.click(processor.process, inputs=text_input, outputs=[bibtex_output])
|
217 |
-
export_button.click(
|
218 |
-
save_bibtex,
|
219 |
-
inputs=[bibtex_output],
|
220 |
-
outputs=[file_output]
|
221 |
-
)
|
222 |
-
|
223 |
-
# Add this JavaScript to enable automatic download
|
224 |
-
demo.load(None, None, None, _js="""
|
225 |
-
function downloadFile(url, filename) {
|
226 |
-
const link = document.createElement('a');
|
227 |
-
link.href = url;
|
228 |
-
link.download = filename;
|
229 |
-
document.body.appendChild(link);
|
230 |
-
link.click();
|
231 |
-
document.body.removeChild(link);
|
232 |
-
}
|
233 |
-
|
234 |
-
// Observe changes to the File component
|
235 |
-
const observer = new MutationObserver((mutations) => {
|
236 |
-
mutations.forEach((mutation) => {
|
237 |
-
if (mutation.type === 'attributes' && mutation.attributeName === 'href') {
|
238 |
-
const fileComponent = mutation.target;
|
239 |
-
const downloadUrl = fileComponent.href;
|
240 |
-
if (downloadUrl && downloadUrl !== '#') {
|
241 |
-
downloadFile(downloadUrl, 'bibliography.bib');
|
242 |
-
// Reset the href to prevent repeated downloads
|
243 |
-
fileComponent.setAttribute('href', '#');
|
244 |
-
}
|
245 |
-
}
|
246 |
-
});
|
247 |
-
});
|
248 |
-
|
249 |
-
// Start observing the File component once it's available
|
250 |
-
function observeFileComponent() {
|
251 |
-
const fileComponent = document.querySelector('.file-preview');
|
252 |
-
if (fileComponent) {
|
253 |
-
observer.observe(fileComponent, { attributes: true });
|
254 |
-
} else {
|
255 |
-
setTimeout(observeFileComponent, 100);
|
256 |
-
}
|
257 |
-
}
|
258 |
|
259 |
-
observeFileComponent();
|
260 |
-
""")
|
261 |
if __name__ == "__main__":
|
262 |
demo.queue().launch()
|
|
|
121 |
|
122 |
#Pages conformity.
|
123 |
if 'pages' in data:
|
124 |
+
match = re.search(r'(\d+(-\d+)?)', data['pages'])
|
125 |
if match:
|
126 |
data['pages'] = match.group(1)
|
127 |
else:
|
|
|
201 |
# Create the processor instance
|
202 |
processor = CombinedProcessor()
|
203 |
|
204 |
+
# Define the Gradio interface
|
205 |
with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
206 |
+
gr.HTML("""<h1 style="text-align:center">Reversed Zotero 2</h1>""")
|
207 |
text_input = gr.Textbox(label="Your text", type="text", lines=10)
|
208 |
text_button = gr.Button("Process Text")
|
209 |
+
bibtex_output = gr.Textbox(label="BibTeX Entries", lines=15)
|
210 |
|
211 |
+
export_button = gr.Button("Export BibTeX")
|
212 |
+
export_output = gr.File(label="Exported BibTeX File")
|
|
|
|
|
|
|
213 |
|
214 |
text_button.click(processor.process, inputs=text_input, outputs=[bibtex_output])
|
215 |
+
export_button.click(save_bibtex, inputs=[bibtex_output], outputs=[export_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
|
|
|
|
217 |
if __name__ == "__main__":
|
218 |
demo.queue().launch()
|