Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,73 +19,69 @@ Parameters:
|
|
| 19 |
Returns:
|
| 20 |
- text (str): The extracted text from the specified section range.
|
| 21 |
"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
|
| 53 |
def process_pdf(path):
|
| 54 |
-
|
| 55 |
-
doc = pdfplumber.open(io.BytesIO(path))
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
# """
|
| 88 |
-
# return results_dict
|
| 89 |
|
| 90 |
#json_string = json.dumps(results_dict, indent=4)
|
| 91 |
#print(json_string)
|
|
|
|
| 19 |
Returns:
|
| 20 |
- text (str): The extracted text from the specified section range.
|
| 21 |
"""
|
| 22 |
+
def get_section(path, wanted_section, next_section):
|
| 23 |
+
print(wanted_section)
|
| 24 |
|
| 25 |
+
# Open the PDF file
|
| 26 |
+
doc = pdfplumber.open(io.BytesIO(path))
|
| 27 |
+
start_page = []
|
| 28 |
+
end_page = []
|
| 29 |
|
| 30 |
+
# Find the all the pages for the specified sections
|
| 31 |
+
for page in range(len(doc.pages)):
|
| 32 |
+
if len(doc.pages[page].search(wanted_section, return_chars = False, case = False)) > 0:
|
| 33 |
+
start_page.append(page)
|
| 34 |
+
if len(doc.pages[page].search(next_section, return_chars = False, case = False)) > 0:
|
| 35 |
+
end_page.append(page)
|
| 36 |
+
print(max(start_page))
|
| 37 |
+
print(max(end_page))
|
| 38 |
|
| 39 |
+
# Extract the text between the start and end page of the wanted section
|
| 40 |
+
text = []
|
| 41 |
+
for page_num in range(max(start_page), max(end_page)):
|
| 42 |
+
page = doc.pages[page_num]
|
| 43 |
+
text.append(page.extract_text())
|
| 44 |
+
text = " ".join(text)
|
| 45 |
+
new_text = text.replace("\n", " ")
|
| 46 |
+
special_char_unicode_list = ["\u00e4", "\u00f6", "\u00fc", "\u00df"]
|
| 47 |
+
special_char_replacement_list = ["ae", "oe", "ue", "ss"]
|
| 48 |
+
for index, special_char in enumerate(special_char_unicode_list):
|
| 49 |
+
final_text = new_text.replace(special_char, special_char_replacement_list[index])
|
| 50 |
+
return final_text
|
| 51 |
|
| 52 |
|
| 53 |
def process_pdf(path):
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
results_dict = {}
|
| 56 |
+
results_dict["2.1 Aktualisierte Einordnung des Moduls in das EZ-Programm"] = \
|
| 57 |
+
get_section(path, "2.1 Aktualisierte Einordnung des Moduls in das EZ-Programm", "2.2 Andere Entwicklungsmaßnahmen im konkreten Interventionsbereich des Moduls")
|
| 58 |
+
"""
|
| 59 |
+
results_dict["2.1 Aktualisierte Einordnung des Moduls in das EZ-Programm"] = \
|
| 60 |
+
get_section(path,"2.1 Aktualisierte Einordnung des Moduls in das EZ-Programm", "2.2 Andere Entwicklungsmaßnahmen im konkreten Interventionsbereich des Moduls")
|
| 61 |
+
results_dict["2.2 Andere Entwicklungsmaßnahmen im konkreten Interventionsbereich des Moduls"] = \
|
| 62 |
+
get_section(path, "2.2 Andere Entwicklungsmaßnahmen im konkreten Interventionsbereich des Moduls", "3. Entwicklungen im Interventionsbereich")
|
| 63 |
+
results_dict["3. Entwicklungen im Interventionsbereich"] = \
|
| 64 |
+
get_section(path, "3. Entwicklungen im Interventionsbereich", "4.1 Bewertungen von Zielen, Zielgruppen, Wirkungshypothesen und Indikatoren")
|
| 65 |
+
results_dict["4.1 Bewertungen von Zielen, Zielgruppen, Wirkungshypothesen und Indikatoren"] = \
|
| 66 |
+
get_section(path, "4.1 Bewertungen von Zielen, Zielgruppen, Wirkungshypothesen und Indikatoren", "4.2 Umgesetzte Maßnahmen / Aktivitäten während des Berichtszeitraums")
|
| 67 |
+
results_dict["4.2 Umgesetzte Maßnahmen / Aktivitäten während des Berichtszeitraums"] = \
|
| 68 |
+
get_section(path, "4.2 Umgesetzte Maßnahmen / Aktivitäten während des Berichtszeitraums", "4.3 Umsetzung von Maßnahmen zur Sicherstellung der nachhaltigen Wirksamkeit")
|
| 69 |
+
results_dict["4.3 Umsetzung von Maßnahmen zur Sicherstellung der nachhaltigen Wirksamkeit des Vorhabens"] = \
|
| 70 |
+
get_section(path, "4.3 Umsetzung von Maßnahmen zur Sicherstellung der nachhaltigen Wirksamkeit", "4.4 Laufzeit und Zeitplan")
|
| 71 |
+
results_dict["4.4 Laufzeit und Zeitplan"] = \
|
| 72 |
+
get_section(path, "4.4 Laufzeit und Zeitplan", "4.5 Entstandene Kosten und Kostenverschiebungen")
|
| 73 |
+
results_dict["4.5 Entstandene Kosten und Kostenverschiebungen"] = \
|
| 74 |
+
get_section(path, "4.5 Entstandene Kosten und Kostenverschiebungen", "4.6 Bewertung der Wirkungen und Risiken")
|
| 75 |
+
results_dict["4.6 Bewertung der Wirkungen und Risiken"] = \
|
| 76 |
+
get_section(path, "4.6 Bewertung der Wirkungen und Risiken", "5. Übergeordnete Empfehlungen")
|
| 77 |
+
results_dict["5.1 Empfehlungen und Merkposten für den Politik- und Schwerpunktdialog"] = \
|
| 78 |
+
get_section(path, "5.1 Empfehlungen und Merkposten für den Politik- und Schwerpunktdialog", "5.2 Lernerfahrungen, die für die Länderstrategie und zukünftige EZ-Programme")
|
| 79 |
+
results_dict["5.2 Lernerfahrungen, die für die Länderstrategie und zukünftige EZ-Programme interessant sein könnten"] = \
|
| 80 |
+
get_section(path, "5.2 Lernerfahrungen", "6. Testat")
|
| 81 |
+
results_dict["6. Testat (TZ)"] = \
|
| 82 |
+
get_section(path, "6. Testat", "Anlage 1: Wirkungsmatrix des Moduls")
|
| 83 |
+
"""
|
| 84 |
+
return results_dict
|
|
|
|
|
|
|
| 85 |
|
| 86 |
#json_string = json.dumps(results_dict, indent=4)
|
| 87 |
#print(json_string)
|