andreeabodea commited on
Commit
5772f88
·
verified ·
1 Parent(s): dc64258

Update app.py

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