Upload folder using huggingface_hub
Browse files- src/__pycache__/gradio_app.cpython-39.pyc +0 -0
- src/__pycache__/mailing.cpython-39.pyc +0 -0
- src/__pycache__/prompts.cpython-39.pyc +0 -0
- src/gradio_app.py +54 -14
- src/mailing.py +38 -0
src/__pycache__/gradio_app.cpython-39.pyc
CHANGED
|
Binary files a/src/__pycache__/gradio_app.cpython-39.pyc and b/src/__pycache__/gradio_app.cpython-39.pyc differ
|
|
|
src/__pycache__/mailing.cpython-39.pyc
ADDED
|
Binary file (1.32 kB). View file
|
|
|
src/__pycache__/prompts.cpython-39.pyc
CHANGED
|
Binary files a/src/__pycache__/prompts.cpython-39.pyc and b/src/__pycache__/prompts.cpython-39.pyc differ
|
|
|
src/gradio_app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from langchain.chat_models import ChatOpenAI
|
| 3 |
-
from src.summarization import summarize_wrapper
|
| 4 |
import os
|
| 5 |
|
| 6 |
import pypdfium2 as pdfium
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Function to render a specific page of a PDF file as an image
|
| 10 |
def render_file(file):
|
|
@@ -19,13 +20,6 @@ def render_file(file):
|
|
| 19 |
)
|
| 20 |
images.append((bitmap.to_pil(), f"Seite {page_index+1}"))
|
| 21 |
|
| 22 |
-
# WORK FROM HERE TO RENDER THE COMPLETE PDF
|
| 23 |
-
# bitmap = pdf.render(
|
| 24 |
-
# pdfium.PdfBitmap.to_pil,
|
| 25 |
-
# page_indices=[0, 1, 2],
|
| 26 |
-
# scale=300 / 72, # 300dpi resolution
|
| 27 |
-
# )
|
| 28 |
-
# pil_image = bitmap.to_pil()
|
| 29 |
return gr.update(
|
| 30 |
value=images,
|
| 31 |
)
|
|
@@ -75,24 +69,45 @@ def run_summarization_model_gradio(
|
|
| 75 |
with gr.Row().style(equal_height=True):
|
| 76 |
Header_box = generate_title(title=title, description=description)
|
| 77 |
with gr.Row().style(equal_height=True):
|
| 78 |
-
clear = gr.Button("Clear")
|
| 79 |
file_upload = gr.File(
|
| 80 |
file_count="single",
|
| 81 |
file_types=[".pdf", ".txt"],
|
| 82 |
label="Upload PDF",
|
| 83 |
)
|
| 84 |
-
with gr.Row().style(equal_height=True
|
| 85 |
summary_short = gr.Button("Kurze Zusammenfassung", interactive=False)
|
| 86 |
summary_middle = gr.Button("Mittlere Zusammenfassung", interactive=False)
|
| 87 |
summary_long = gr.Button("Lange Zusammenfassung", interactive=False)
|
| 88 |
with gr.Row().style(equal_height=True):
|
| 89 |
with gr.Column(scale=1):
|
| 90 |
-
summary_output = gr.Textbox(label="Zusammenfassung").style(
|
| 91 |
show_copy_button=True
|
| 92 |
)
|
| 93 |
with gr.Column(scale=1):
|
| 94 |
show_pdf = gr.Gallery(label="Uploaded PDF").style(object_fit="contain")
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Once a file is uploaded, enable the summarization buttons and visualize the uploaded file
|
| 97 |
file_upload.upload(
|
| 98 |
switch_buttons,
|
|
@@ -127,6 +142,11 @@ def run_summarization_model_gradio(
|
|
| 127 |
[gr.State(True)],
|
| 128 |
[summary_short, summary_middle, summary_long],
|
| 129 |
queue=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
)
|
| 131 |
|
| 132 |
# The clear button clears the dashboard
|
|
@@ -137,6 +157,26 @@ def run_summarization_model_gradio(
|
|
| 137 |
[gr.State(False)],
|
| 138 |
[summary_short, summary_middle, summary_long],
|
| 139 |
queue=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
)
|
| 141 |
|
| 142 |
webui.queue()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
import pypdfium2 as pdfium
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
from langchain.chat_models import ChatOpenAI
|
| 7 |
+
from src.summarization import summarize_wrapper
|
| 8 |
+
from src.mailing import send_email
|
| 9 |
|
| 10 |
# Function to render a specific page of a PDF file as an image
|
| 11 |
def render_file(file):
|
|
|
|
| 20 |
)
|
| 21 |
images.append((bitmap.to_pil(), f"Seite {page_index+1}"))
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return gr.update(
|
| 24 |
value=images,
|
| 25 |
)
|
|
|
|
| 69 |
with gr.Row().style(equal_height=True):
|
| 70 |
Header_box = generate_title(title=title, description=description)
|
| 71 |
with gr.Row().style(equal_height=True):
|
| 72 |
+
clear = gr.Button("Clear All Components")
|
| 73 |
file_upload = gr.File(
|
| 74 |
file_count="single",
|
| 75 |
file_types=[".pdf", ".txt"],
|
| 76 |
label="Upload PDF",
|
| 77 |
)
|
| 78 |
+
with gr.Row().style(equal_height=True):
|
| 79 |
summary_short = gr.Button("Kurze Zusammenfassung", interactive=False)
|
| 80 |
summary_middle = gr.Button("Mittlere Zusammenfassung", interactive=False)
|
| 81 |
summary_long = gr.Button("Lange Zusammenfassung", interactive=False)
|
| 82 |
with gr.Row().style(equal_height=True):
|
| 83 |
with gr.Column(scale=1):
|
| 84 |
+
summary_output = gr.Textbox(label="Zusammenfassung", lines=9).style(
|
| 85 |
show_copy_button=True
|
| 86 |
)
|
| 87 |
with gr.Column(scale=1):
|
| 88 |
show_pdf = gr.Gallery(label="Uploaded PDF").style(object_fit="contain")
|
| 89 |
|
| 90 |
+
with gr.Row().style(equal_height=True):
|
| 91 |
+
with gr.Column(scale=1):
|
| 92 |
+
recipiant_email = gr.Textbox(
|
| 93 |
+
label="Recipiant Email", placeholder="Enter Email"
|
| 94 |
+
)
|
| 95 |
+
subject_email = gr.Textbox(label="Subject", placeholder="Enter Subject")
|
| 96 |
+
send_email_button = gr.Button("Open Email", interactive=False)
|
| 97 |
+
with gr.Column(scale=3):
|
| 98 |
+
email_instructions = gr.Textbox(
|
| 99 |
+
label="Email Instructions",
|
| 100 |
+
placeholder="Write Email Instructions here.",
|
| 101 |
+
value=(
|
| 102 |
+
"Dear Recipient\n\n"
|
| 103 |
+
"Please find the summarization of the uploaded document below.\n\n"
|
| 104 |
+
"<TEXT_FROM_LLM>\n\n"
|
| 105 |
+
"Kind regards,\n"
|
| 106 |
+
"Your Legal Assistant"
|
| 107 |
+
),
|
| 108 |
+
lines=9,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
# Once a file is uploaded, enable the summarization buttons and visualize the uploaded file
|
| 112 |
file_upload.upload(
|
| 113 |
switch_buttons,
|
|
|
|
| 142 |
[gr.State(True)],
|
| 143 |
[summary_short, summary_middle, summary_long],
|
| 144 |
queue=False,
|
| 145 |
+
).then(
|
| 146 |
+
switch_buttons,
|
| 147 |
+
[gr.State(True)],
|
| 148 |
+
[send_email_button, gr.State(None), gr.State(None)],
|
| 149 |
+
queue=False,
|
| 150 |
)
|
| 151 |
|
| 152 |
# The clear button clears the dashboard
|
|
|
|
| 157 |
[gr.State(False)],
|
| 158 |
[summary_short, summary_middle, summary_long],
|
| 159 |
queue=False,
|
| 160 |
+
).then(
|
| 161 |
+
lambda: None, None, show_pdf, queue=False
|
| 162 |
+
).then(
|
| 163 |
+
lambda: None, None, send_email_button, queue=False
|
| 164 |
+
).then(
|
| 165 |
+
lambda: None, None, email_instructions, queue=False
|
| 166 |
+
).then(
|
| 167 |
+
lambda: None, None, recipiant_email, queue=False
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
# Email button click opens the default email client and fills in the email instructions
|
| 171 |
+
send_email_button.click(
|
| 172 |
+
send_email,
|
| 173 |
+
[
|
| 174 |
+
summary_output,
|
| 175 |
+
recipiant_email,
|
| 176 |
+
subject_email,
|
| 177 |
+
email_instructions,
|
| 178 |
+
],
|
| 179 |
+
queue=False,
|
| 180 |
)
|
| 181 |
|
| 182 |
webui.queue()
|
src/mailing.py
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import webbrowser
|
| 2 |
+
import urllib.parse
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def send_email(
|
| 7 |
+
llm_text: str,
|
| 8 |
+
recipients: str = "",
|
| 9 |
+
subject: str = "",
|
| 10 |
+
email_wrapping_content: str = "<TEXT_FROM_LLM>",
|
| 11 |
+
):
|
| 12 |
+
"""Send an email to the specified recipients.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
recipients (List[str], optional): List of email addresses. Defaults to [""].
|
| 16 |
+
subject (str): Subject of the email.
|
| 17 |
+
email_content (_type_): Content of the email.
|
| 18 |
+
|
| 19 |
+
Example usage:
|
| 20 |
+
- send_email("test@example.com;test2@example.com", "Hello!", "This is the body of the email.")
|
| 21 |
+
"""
|
| 22 |
+
recipients_list = recipients.split(";")
|
| 23 |
+
email_addresses = ",".join([recipient.strip() for recipient in recipients_list])
|
| 24 |
+
|
| 25 |
+
# URL encode the subject and email content to ensure it's correctly parsed
|
| 26 |
+
subject = urllib.parse.quote(subject)
|
| 27 |
+
|
| 28 |
+
if "<TEXT_FROM_LLM>" in email_wrapping_content:
|
| 29 |
+
email_content = email_wrapping_content.replace("<TEXT_FROM_LLM>", llm_text)
|
| 30 |
+
else:
|
| 31 |
+
email_content = email_wrapping_content + "\n\n" + llm_text
|
| 32 |
+
email_content = urllib.parse.quote(email_content)
|
| 33 |
+
|
| 34 |
+
# Construct the mailto URL
|
| 35 |
+
mailto_url = f"mailto:{email_addresses}?subject={subject}&body={email_content}"
|
| 36 |
+
|
| 37 |
+
# Open the default email client
|
| 38 |
+
webbrowser.open(mailto_url)
|