darisdzakwanhoesien commited on
Commit
93118f1
·
verified ·
1 Parent(s): d534b60

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import bibtexparser
4
+ from io import StringIO
5
+
6
+ def bib_to_csv(bib_file):
7
+ try:
8
+ # Read uploaded file
9
+ content = bib_file.read().decode("utf-8")
10
+ bib_db = bibtexparser.load(StringIO(content))
11
+
12
+ # Convert entries to DataFrame
13
+ df = pd.DataFrame(bib_db.entries)
14
+
15
+ # Create downloadable CSV
16
+ csv_buffer = StringIO()
17
+ df.to_csv(csv_buffer, index=False)
18
+ csv_bytes = csv_buffer.getvalue().encode("utf-8")
19
+
20
+ return df, csv_bytes
21
+ except Exception as e:
22
+ return pd.DataFrame({"Error": [str(e)]}), None
23
+
24
+
25
+ with gr.Blocks(title="BibTeX → CSV Converter") as demo:
26
+ gr.Markdown("## 📚 BibTeX to CSV Converter\nUpload a `.bib` file to extract references into CSV format.")
27
+
28
+ with gr.Row():
29
+ bib_input = gr.File(label="Upload your .bib file", file_types=[".bib"])
30
+ convert_btn = gr.Button("Convert")
31
+
32
+ with gr.Row():
33
+ output_table = gr.DataFrame(label="Parsed Bibliography Preview")
34
+ output_file = gr.File(label="Download CSV")
35
+
36
+ convert_btn.click(fn=bib_to_csv, inputs=bib_input, outputs=[output_table, output_file])
37
+
38
+ demo.launch()