Delete convertjson.py
Browse files- convertjson.py +0 -32
convertjson.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
import pdfplumber
|
| 2 |
-
import jsonlines
|
| 3 |
-
|
| 4 |
-
# Funci贸n para extraer texto de un PDF usando pdfplumber
|
| 5 |
-
def extract_text_from_pdf(pdf_path):
|
| 6 |
-
text = ""
|
| 7 |
-
with pdfplumber.open(pdf_path) as pdf:
|
| 8 |
-
for page in pdf.pages:
|
| 9 |
-
text += page.extract_text() + "\n"
|
| 10 |
-
return text
|
| 11 |
-
|
| 12 |
-
# Funci贸n para convertir texto en formato JSONL
|
| 13 |
-
def convert_to_jsonl(text, output_file):
|
| 14 |
-
lines = text.split("\n") # Dividimos el texto en l铆neas o por secciones que desees
|
| 15 |
-
with jsonlines.open(output_file, mode='w') as writer:
|
| 16 |
-
for line in lines:
|
| 17 |
-
if line.strip(): # Evitamos escribir l铆neas vac铆as
|
| 18 |
-
data = {"prompt": "Pregunta al estilo [ ]", "response": line.strip()}
|
| 19 |
-
writer.write(data)
|
| 20 |
-
|
| 21 |
-
# Ruta del PDF de entrada y el archivo JSONL de salida
|
| 22 |
-
pdf_path = "/Users/acavalarutadondeestaelpdf" # Ruta del PDF
|
| 23 |
-
output_jsonl_path = "/Users/acalacarpetadondequeremosquesealojeeljson/output.jsonl" # Ruta del archivo JSONL
|
| 24 |
-
|
| 25 |
-
# Extraer texto del PDF
|
| 26 |
-
extracted_text = extract_text_from_pdf(pdf_path)
|
| 27 |
-
|
| 28 |
-
# Convertir el texto extra铆do a JSONL
|
| 29 |
-
convert_to_jsonl(extracted_text, output_jsonl_path)
|
| 30 |
-
|
| 31 |
-
print(f"Archivo JSONL guardado en {output_jsonl_path}")
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|