Upload folder using huggingface_hub
Browse files- app.py +0 -1
- src/__pycache__/gradio_app.cpython-311.pyc +0 -0
- src/__pycache__/llm_utils.cpython-311.pyc +0 -0
- src/__pycache__/prompts.cpython-311.pyc +0 -0
- src/__pycache__/summarization.cpython-311.pyc +0 -0
- src/gradio_app.py +10 -13
- src/prompts.py +3 -42
- src/summarization.py +5 -14
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import json
|
|
| 3 |
|
| 4 |
from src.gradio_app import run_summarization_model_gradio
|
| 5 |
from src.model_loading import load_open_ai_llm
|
| 6 |
-
from src.prompts import prompts
|
| 7 |
|
| 8 |
parser = argparse.ArgumentParser(description="Defines a configuration")
|
| 9 |
|
|
|
|
| 3 |
|
| 4 |
from src.gradio_app import run_summarization_model_gradio
|
| 5 |
from src.model_loading import load_open_ai_llm
|
|
|
|
| 6 |
|
| 7 |
parser = argparse.ArgumentParser(description="Defines a configuration")
|
| 8 |
|
src/__pycache__/gradio_app.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/gradio_app.cpython-311.pyc and b/src/__pycache__/gradio_app.cpython-311.pyc differ
|
|
|
src/__pycache__/llm_utils.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/llm_utils.cpython-311.pyc and b/src/__pycache__/llm_utils.cpython-311.pyc differ
|
|
|
src/__pycache__/prompts.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/prompts.cpython-311.pyc and b/src/__pycache__/prompts.cpython-311.pyc differ
|
|
|
src/__pycache__/summarization.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/summarization.cpython-311.pyc and b/src/__pycache__/summarization.cpython-311.pyc differ
|
|
|
src/gradio_app.py
CHANGED
|
@@ -86,9 +86,7 @@ def load_summary_section(llm: ChatOpenAI):
|
|
| 86 |
file_types=[".pdf", ".txt"],
|
| 87 |
label="Upload PDF",
|
| 88 |
)
|
| 89 |
-
summary_parallel_button = gr.Button(
|
| 90 |
-
"Summarize", interactive=False
|
| 91 |
-
)
|
| 92 |
clear_button = gr.Button("Clear All")
|
| 93 |
with gr.Column(scale=2):
|
| 94 |
sections_to_select = [
|
|
@@ -103,19 +101,19 @@ def load_summary_section(llm: ChatOpenAI):
|
|
| 103 |
info="Select the sections you want to include in the summarization.",
|
| 104 |
)
|
| 105 |
with gr.Row().style(equal_height=True):
|
| 106 |
-
with gr.Column(scale=1):
|
| 107 |
-
summary_output = gr.Textbox(label="Summary", lines=9).style(
|
| 108 |
-
show_copy_button=True
|
| 109 |
-
)
|
| 110 |
with gr.Column(scale=1):
|
| 111 |
summary_show_pdf = gr.Gallery(label="Uploaded PDF").style(
|
| 112 |
object_fit="contain"
|
| 113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
with gr.Row().style(equal_height=True):
|
| 116 |
with gr.Column(scale=1):
|
| 117 |
recipiant_email_summary = gr.Textbox(
|
| 118 |
-
label="
|
| 119 |
)
|
| 120 |
subject_email_summary = gr.Textbox(
|
| 121 |
label="Subject", placeholder="Enter Subject"
|
|
@@ -196,7 +194,6 @@ def load_legal_implications_section(llm: ChatOpenAI, summarization_kwargs: dict
|
|
| 196 |
gr.Block: Legal Implications Section
|
| 197 |
"""
|
| 198 |
with gr.Blocks(theme="soft") as legal_implications_section:
|
| 199 |
-
|
| 200 |
with gr.Row().style(equal_height=True):
|
| 201 |
with gr.Column(scale=3):
|
| 202 |
file_upload_legal_implications = gr.File(
|
|
@@ -211,14 +208,14 @@ def load_legal_implications_section(llm: ChatOpenAI, summarization_kwargs: dict
|
|
| 211 |
clear_legal_implications_button = gr.Button("Clear All")
|
| 212 |
|
| 213 |
with gr.Row().style(equal_height=True):
|
| 214 |
-
with gr.Column(scale=1):
|
| 215 |
-
legal_implications_output = gr.Textbox(
|
| 216 |
-
label="Legal Implications", lines=9
|
| 217 |
-
).style(show_copy_button=True)
|
| 218 |
with gr.Column(scale=1):
|
| 219 |
legal_implications_show_pdf = gr.Gallery(label="Uploaded PDF").style(
|
| 220 |
object_fit="contain"
|
| 221 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
with gr.Row().style(equal_height=True):
|
| 224 |
with gr.Column(scale=1):
|
|
|
|
| 86 |
file_types=[".pdf", ".txt"],
|
| 87 |
label="Upload PDF",
|
| 88 |
)
|
| 89 |
+
summary_parallel_button = gr.Button("Summarize", interactive=False)
|
|
|
|
|
|
|
| 90 |
clear_button = gr.Button("Clear All")
|
| 91 |
with gr.Column(scale=2):
|
| 92 |
sections_to_select = [
|
|
|
|
| 101 |
info="Select the sections you want to include in the summarization.",
|
| 102 |
)
|
| 103 |
with gr.Row().style(equal_height=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
with gr.Column(scale=1):
|
| 105 |
summary_show_pdf = gr.Gallery(label="Uploaded PDF").style(
|
| 106 |
object_fit="contain"
|
| 107 |
)
|
| 108 |
+
with gr.Column(scale=1):
|
| 109 |
+
summary_output = gr.Textbox(label="Summary", lines=9).style(
|
| 110 |
+
show_copy_button=True
|
| 111 |
+
)
|
| 112 |
|
| 113 |
with gr.Row().style(equal_height=True):
|
| 114 |
with gr.Column(scale=1):
|
| 115 |
recipiant_email_summary = gr.Textbox(
|
| 116 |
+
label="Recipient Email", placeholder="Enter Email"
|
| 117 |
)
|
| 118 |
subject_email_summary = gr.Textbox(
|
| 119 |
label="Subject", placeholder="Enter Subject"
|
|
|
|
| 194 |
gr.Block: Legal Implications Section
|
| 195 |
"""
|
| 196 |
with gr.Blocks(theme="soft") as legal_implications_section:
|
|
|
|
| 197 |
with gr.Row().style(equal_height=True):
|
| 198 |
with gr.Column(scale=3):
|
| 199 |
file_upload_legal_implications = gr.File(
|
|
|
|
| 208 |
clear_legal_implications_button = gr.Button("Clear All")
|
| 209 |
|
| 210 |
with gr.Row().style(equal_height=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
with gr.Column(scale=1):
|
| 212 |
legal_implications_show_pdf = gr.Gallery(label="Uploaded PDF").style(
|
| 213 |
object_fit="contain"
|
| 214 |
)
|
| 215 |
+
with gr.Column(scale=1):
|
| 216 |
+
legal_implications_output = gr.Textbox(
|
| 217 |
+
label="Legal Implications", lines=9
|
| 218 |
+
).style(show_copy_button=True)
|
| 219 |
|
| 220 |
with gr.Row().style(equal_height=True):
|
| 221 |
with gr.Column(scale=1):
|
src/prompts.py
CHANGED
|
@@ -164,6 +164,7 @@ def get_template_parallel(name: str, headline: str, additional_text: str = ""):
|
|
| 164 |
"Schreibe, ein/e <KEY> des Urteils, das durch dreifache Anführungszeichen begrenzt ist, in maximal einem Paragraphen.\n"
|
| 165 |
"<ADDITIONAL_TEXT>\n"
|
| 166 |
'Als Überschrift muss "<HEAD_LINE>" angegeben werden. \n'
|
|
|
|
| 167 |
"Urteil:\n"
|
| 168 |
"```{text}```\n"
|
| 169 |
"\n"
|
|
@@ -210,7 +211,7 @@ prompts_parallel_summary = {
|
|
| 210 |
"prozessgeschichte": PromptTemplate(
|
| 211 |
input_variables=["text"],
|
| 212 |
template=get_template_parallel(
|
| 213 |
-
name="Prozessgeschichte", headline="
|
| 214 |
),
|
| 215 |
),
|
| 216 |
"rechtsproblem": PromptTemplate(
|
|
@@ -227,46 +228,6 @@ prompts_parallel_summary = {
|
|
| 227 |
name="Lösung des Gerichts", headline="Lösung des Gerichts"
|
| 228 |
),
|
| 229 |
),
|
| 230 |
-
"loesungsansaetze_zum_problem": PromptTemplate(
|
| 231 |
-
input_variables=["text"],
|
| 232 |
-
template=get_template_parallel(
|
| 233 |
-
name="Lösungsansätze zum Problem",
|
| 234 |
-
headline="Lösungsansätze zum Problem",
|
| 235 |
-
additional_text="Knappe, aber möglichst vollständige Übersicht der vertretenen Ansichten bzw. der Lösungsvorschläge im Urteil.",
|
| 236 |
-
),
|
| 237 |
-
),
|
| 238 |
-
"analyse_und_einordnung_der_entscheidung": PromptTemplate(
|
| 239 |
-
input_variables=["text"],
|
| 240 |
-
template=get_template_parallel(
|
| 241 |
-
name="Analyse und Einordnung der Entscheidung",
|
| 242 |
-
headline="Analyse und Einordnung der Entscheidung",
|
| 243 |
-
additional_text="Es soll nur der Inhalt des Urteils wiedergegeben werden.",
|
| 244 |
-
),
|
| 245 |
-
),
|
| 246 |
-
"bewertung_und_kritik_der_entscheidung": PromptTemplate(
|
| 247 |
-
input_variables=["text"],
|
| 248 |
-
template=get_template_parallel(
|
| 249 |
-
name="Bewertung und Kritik der Entscheidung",
|
| 250 |
-
headline="Bewertung und Kritik der Entscheidung",
|
| 251 |
-
additional_text="Verwende ausschließlich den Kontext des Urteils und schreib keinen neuen Text. Wenn keine Bewertung oder Kritik vorhanden ist, antworte mit 'Keine Bewertung oder Kritik vorhanden.'",
|
| 252 |
-
),
|
| 253 |
-
),
|
| 254 |
-
"eigener_loesungsvorschlag": PromptTemplate(
|
| 255 |
-
input_variables=["text"],
|
| 256 |
-
template=get_template_parallel(
|
| 257 |
-
name="Eigener Lösungsvorschlag",
|
| 258 |
-
headline="Eigener Lösungsvorschlag",
|
| 259 |
-
additional_text="Es soll nur der Inhalt des Urteils wiedergegeben werden. Wenn das Urteil keinen eigenen Lösungsvorschlag hat schreib: 'Keine Informationen zum eigenen Lösungsvorschlag vorhanden'",
|
| 260 |
-
),
|
| 261 |
-
),
|
| 262 |
-
"ausblick": PromptTemplate(
|
| 263 |
-
input_variables=["text"],
|
| 264 |
-
template=get_template_parallel(
|
| 265 |
-
name="Ausblick",
|
| 266 |
-
headline="Ausblick",
|
| 267 |
-
additional_text="Es soll nur der Inhalt des Urteils wiedergegeben werden. Wenn das Urteil keinen Ausblick gibt schreib: 'Keine Informationen zum Auslbick vorhanden'.",
|
| 268 |
-
),
|
| 269 |
-
),
|
| 270 |
}
|
| 271 |
|
| 272 |
prompts_parallel_legal_implications = {
|
|
@@ -295,7 +256,7 @@ Die folgenden rechtlich relvanten Fakten als Stichpunkte sind durch dreifache An
|
|
| 295 |
Rechlich relvanten Fakten:
|
| 296 |
```{text}```
|
| 297 |
|
| 298 |
-
Schreibe einen rechtlich korrekten Text, der die
|
| 299 |
Schreibe zu jedem rechtlich relevantem Fakt einen kurzen Paragraphen mit sehr wenig Sätzen, der erklärt warum dies rechtlich relevant ist.
|
| 300 |
Der Text muss zu 100% korrekt sein!
|
| 301 |
|
|
|
|
| 164 |
"Schreibe, ein/e <KEY> des Urteils, das durch dreifache Anführungszeichen begrenzt ist, in maximal einem Paragraphen.\n"
|
| 165 |
"<ADDITIONAL_TEXT>\n"
|
| 166 |
'Als Überschrift muss "<HEAD_LINE>" angegeben werden. \n'
|
| 167 |
+
"Es muss die korrekte Seite aus der der Kontext stammt mit angegeben werden. Z.B. (siehe Seite ?) \n"
|
| 168 |
"Urteil:\n"
|
| 169 |
"```{text}```\n"
|
| 170 |
"\n"
|
|
|
|
| 211 |
"prozessgeschichte": PromptTemplate(
|
| 212 |
input_variables=["text"],
|
| 213 |
template=get_template_parallel(
|
| 214 |
+
name="Prozessgeschichte", headline="Prozessgeschichte"
|
| 215 |
),
|
| 216 |
),
|
| 217 |
"rechtsproblem": PromptTemplate(
|
|
|
|
| 228 |
name="Lösung des Gerichts", headline="Lösung des Gerichts"
|
| 229 |
),
|
| 230 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
}
|
| 232 |
|
| 233 |
prompts_parallel_legal_implications = {
|
|
|
|
| 256 |
Rechlich relvanten Fakten:
|
| 257 |
```{text}```
|
| 258 |
|
| 259 |
+
Schreibe einen rechtlich korrekten Text, der die rechtlich relvanten Fakten auflistet.
|
| 260 |
Schreibe zu jedem rechtlich relevantem Fakt einen kurzen Paragraphen mit sehr wenig Sätzen, der erklärt warum dies rechtlich relevant ist.
|
| 261 |
Der Text muss zu 100% korrekt sein!
|
| 262 |
|
src/summarization.py
CHANGED
|
@@ -5,7 +5,7 @@ from src.prompts import (
|
|
| 5 |
prompts_parallel_summary,
|
| 6 |
)
|
| 7 |
from src.doc_loading import load_docs
|
| 8 |
-
from src.llm_utils import async_generate_llmchain
|
| 9 |
import time
|
| 10 |
from typing import Dict, List
|
| 11 |
import asyncio
|
|
@@ -123,12 +123,6 @@ PARALLEL_SUMMARIZATION_ORDER = [
|
|
| 123 |
"prozessgeschichte",
|
| 124 |
"rechtsproblem",
|
| 125 |
"loesung_des_gerichts",
|
| 126 |
-
"III. Analyse",
|
| 127 |
-
"loesungsansaetze_zum_problem",
|
| 128 |
-
"analyse_und_einordnung_der_entscheidung",
|
| 129 |
-
"bewertung_und_kritik_der_entscheidung",
|
| 130 |
-
"eigener_loesungsvorschlag",
|
| 131 |
-
"ausblick",
|
| 132 |
]
|
| 133 |
PARALLEL_SUMMARIZATION_MAPPING = {
|
| 134 |
"I. Einleitung": "intro",
|
|
@@ -138,11 +132,6 @@ PARALLEL_SUMMARIZATION_MAPPING = {
|
|
| 138 |
"Prozessgeschichte": "prozessgeschichte",
|
| 139 |
"Rechtsproblem": "rechtsproblem",
|
| 140 |
"Lösung des Gerichts": "loesung_des_gerichts",
|
| 141 |
-
"Lösungsansätze zum Problem": "loesungsansaetze_zum_problem",
|
| 142 |
-
"Analyse und Einordnung der Entscheidung": "analyse_und_einordnung_der_entscheidung",
|
| 143 |
-
"Bewertung und Kritik der Entscheidung": "bewertung_und_kritik_der_entscheidung",
|
| 144 |
-
"Eigener Lösungsvorschlag": "eigener_loesungsvorschlag",
|
| 145 |
-
"Ausblick": "ausblick",
|
| 146 |
}
|
| 147 |
PARALLEL_SUMMARIZATION_MAPPING_INVERSE = {
|
| 148 |
v: k for k, v in PARALLEL_SUMMARIZATION_MAPPING.items()
|
|
@@ -161,15 +150,17 @@ def parallel_summarization(file: str, sections: List[str], llm: ChatOpenAI) -> s
|
|
| 161 |
str: Summarization of the file.
|
| 162 |
"""
|
| 163 |
now = time.time()
|
|
|
|
| 164 |
values_flattened = asyncio.run(
|
| 165 |
generate_summary_concurrently(
|
| 166 |
file_path=file.name, sections=sections, llm=llm[0]
|
| 167 |
)
|
| 168 |
)
|
|
|
|
| 169 |
print("Time taken for complete parallel summarization: ", time.time() - now)
|
| 170 |
-
order = PARALLEL_SUMMARIZATION_ORDER
|
| 171 |
output = ""
|
| 172 |
-
|
|
|
|
| 173 |
output += (
|
| 174 |
values_flattened.get(
|
| 175 |
section, PARALLEL_SUMMARIZATION_MAPPING_INVERSE.get(section, section)
|
|
|
|
| 5 |
prompts_parallel_summary,
|
| 6 |
)
|
| 7 |
from src.doc_loading import load_docs
|
| 8 |
+
from src.llm_utils import async_generate_llmchain
|
| 9 |
import time
|
| 10 |
from typing import Dict, List
|
| 11 |
import asyncio
|
|
|
|
| 123 |
"prozessgeschichte",
|
| 124 |
"rechtsproblem",
|
| 125 |
"loesung_des_gerichts",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
]
|
| 127 |
PARALLEL_SUMMARIZATION_MAPPING = {
|
| 128 |
"I. Einleitung": "intro",
|
|
|
|
| 132 |
"Prozessgeschichte": "prozessgeschichte",
|
| 133 |
"Rechtsproblem": "rechtsproblem",
|
| 134 |
"Lösung des Gerichts": "loesung_des_gerichts",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
PARALLEL_SUMMARIZATION_MAPPING_INVERSE = {
|
| 137 |
v: k for k, v in PARALLEL_SUMMARIZATION_MAPPING.items()
|
|
|
|
| 150 |
str: Summarization of the file.
|
| 151 |
"""
|
| 152 |
now = time.time()
|
| 153 |
+
|
| 154 |
values_flattened = asyncio.run(
|
| 155 |
generate_summary_concurrently(
|
| 156 |
file_path=file.name, sections=sections, llm=llm[0]
|
| 157 |
)
|
| 158 |
)
|
| 159 |
+
|
| 160 |
print("Time taken for complete parallel summarization: ", time.time() - now)
|
|
|
|
| 161 |
output = ""
|
| 162 |
+
|
| 163 |
+
for section in values_flattened.keys():
|
| 164 |
output += (
|
| 165 |
values_flattened.get(
|
| 166 |
section, PARALLEL_SUMMARIZATION_MAPPING_INVERSE.get(section, section)
|