namelessai commited on
Commit
d8681bc
·
verified ·
1 Parent(s): 6770c2c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import PyPDF2
4
+ import markdown
5
+
6
+ def convert_to_jsonl(file):
7
+ content = ""
8
+ if file.name.endswith('.txt'):
9
+ content = file.read().decode('utf-8')
10
+ elif file.name.endswith('.pdf'):
11
+ pdf_reader = PyPDF2.PdfReader(file)
12
+ for page in pdf_reader.pages:
13
+ content += page.extract_text()
14
+ elif file.name.endswith('.md'):
15
+ content = file.read().decode('utf-8')
16
+ content = markdown.markdown(content)
17
+
18
+ lines = content.split('\n')
19
+ jsonl_output = ""
20
+ for i, line in enumerate(lines):
21
+ if line.strip():
22
+ json_obj = {"id": i, "text": line.strip()}
23
+ jsonl_output += json.dumps(json_obj) + "\n"
24
+
25
+ return jsonl_output
26
+
27
+ iface = gr.Interface(
28
+ fn=convert_to_jsonl,
29
+ inputs=gr.File(label="Upload .txt, .pdf, or .md file"),
30
+ outputs=gr.File(label="Download JSONL file"),
31
+ title="Raw Text to Indexed JSONL Converter",
32
+ description="Upload a .txt, .pdf, or .md file to convert it to an indexed JSONL file for LLM training."
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ iface.launch()