Upload folder using huggingface_hub
Browse files- __pycache__/__init__.cpython-311.pyc +0 -0
- src/__pycache__/doc_loading.cpython-311.pyc +0 -0
- src/__pycache__/email_sender.cpython-311.pyc +0 -0
- src/__pycache__/gradio_app.cpython-311.pyc +0 -0
- src/__pycache__/legal_implications.cpython-311.pyc +0 -0
- src/__pycache__/llm_utils.cpython-311.pyc +0 -0
- src/__pycache__/mailing.cpython-311.pyc +0 -0
- src/__pycache__/model_loading.cpython-311.pyc +0 -0
- src/__pycache__/prompts.cpython-311.pyc +0 -0
- src/__pycache__/summarization.cpython-311.pyc +0 -0
- src/email_sender.py +320 -0
__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (174 Bytes). View file
|
|
|
src/__pycache__/doc_loading.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/doc_loading.cpython-311.pyc and b/src/__pycache__/doc_loading.cpython-311.pyc differ
|
|
|
src/__pycache__/email_sender.cpython-311.pyc
ADDED
|
Binary file (16 kB). View file
|
|
|
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__/legal_implications.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/legal_implications.cpython-311.pyc and b/src/__pycache__/legal_implications.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__/mailing.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/mailing.cpython-311.pyc and b/src/__pycache__/mailing.cpython-311.pyc differ
|
|
|
src/__pycache__/model_loading.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/model_loading.cpython-311.pyc and b/src/__pycache__/model_loading.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/email_sender.py
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
"""Utilities for opening files or URLs in the registered default application
|
| 4 |
+
and for sending e-mail using the user's preferred composer.
|
| 5 |
+
|
| 6 |
+
https://stackoverflow.com/a/19779373/3211506
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
__version__ = "1.1"
|
| 11 |
+
__all__ = ["open", "mailto"]
|
| 12 |
+
|
| 13 |
+
import os
|
| 14 |
+
import sys
|
| 15 |
+
import webbrowser
|
| 16 |
+
import subprocess
|
| 17 |
+
|
| 18 |
+
from email.utils import encode_rfc2231
|
| 19 |
+
|
| 20 |
+
_controllers = {}
|
| 21 |
+
_open = None
|
| 22 |
+
|
| 23 |
+
fileopen = open
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class BaseController(object):
|
| 27 |
+
"""Base class for open program controllers."""
|
| 28 |
+
|
| 29 |
+
def __init__(self, name):
|
| 30 |
+
self.name = name
|
| 31 |
+
|
| 32 |
+
def open(self, filename):
|
| 33 |
+
raise NotImplementedError
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class Controller(BaseController):
|
| 37 |
+
"""Controller for a generic open program."""
|
| 38 |
+
|
| 39 |
+
def __init__(self, *args):
|
| 40 |
+
super(Controller, self).__init__(os.path.basename(args[0]))
|
| 41 |
+
self.args = list(args)
|
| 42 |
+
|
| 43 |
+
def _invoke(self, cmdline):
|
| 44 |
+
if sys.platform[:3] == "win":
|
| 45 |
+
closefds = False
|
| 46 |
+
startupinfo = subprocess.STARTUPINFO()
|
| 47 |
+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
| 48 |
+
else:
|
| 49 |
+
closefds = True
|
| 50 |
+
startupinfo = None
|
| 51 |
+
|
| 52 |
+
if (
|
| 53 |
+
os.environ.get("DISPLAY")
|
| 54 |
+
or sys.platform[:3] == "win"
|
| 55 |
+
or sys.platform == "darwin"
|
| 56 |
+
):
|
| 57 |
+
inout = fileopen(os.devnull, "r+")
|
| 58 |
+
else:
|
| 59 |
+
# for TTY programs, we need stdin/out
|
| 60 |
+
inout = None
|
| 61 |
+
|
| 62 |
+
# if possible, put the child precess in separate process group,
|
| 63 |
+
# so keyboard interrupts don't affect child precess as well as
|
| 64 |
+
# Python
|
| 65 |
+
setsid = getattr(os, "setsid", None)
|
| 66 |
+
if not setsid:
|
| 67 |
+
setsid = getattr(os, "setpgrp", None)
|
| 68 |
+
|
| 69 |
+
pipe = subprocess.Popen(
|
| 70 |
+
cmdline,
|
| 71 |
+
stdin=inout,
|
| 72 |
+
stdout=inout,
|
| 73 |
+
stderr=inout,
|
| 74 |
+
close_fds=closefds,
|
| 75 |
+
preexec_fn=setsid,
|
| 76 |
+
startupinfo=startupinfo,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# It is assumed that this kind of tools (gnome-open, kfmclient,
|
| 80 |
+
# exo-open, xdg-open and open for OSX) immediately exit after lauching
|
| 81 |
+
# the specific application
|
| 82 |
+
returncode = pipe.wait()
|
| 83 |
+
if hasattr(self, "fixreturncode"):
|
| 84 |
+
returncode = self.fixreturncode(returncode)
|
| 85 |
+
return not returncode
|
| 86 |
+
|
| 87 |
+
def open(self, filename):
|
| 88 |
+
if isinstance(filename, str):
|
| 89 |
+
cmdline = self.args + [filename]
|
| 90 |
+
else:
|
| 91 |
+
# assume it is a sequence
|
| 92 |
+
cmdline = self.args + filename
|
| 93 |
+
try:
|
| 94 |
+
return self._invoke(cmdline)
|
| 95 |
+
except OSError:
|
| 96 |
+
return False
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# Platform support for Windows
|
| 100 |
+
if sys.platform[:3] == "win":
|
| 101 |
+
|
| 102 |
+
class Start(BaseController):
|
| 103 |
+
"""Controller for the win32 start progam through os.startfile."""
|
| 104 |
+
|
| 105 |
+
def open(self, filename):
|
| 106 |
+
try:
|
| 107 |
+
os.startfile(filename)
|
| 108 |
+
except WindowsError:
|
| 109 |
+
# [Error 22] No application is associated with the specified
|
| 110 |
+
# file for this operation: '<URL>'
|
| 111 |
+
return False
|
| 112 |
+
else:
|
| 113 |
+
return True
|
| 114 |
+
|
| 115 |
+
_controllers["windows-default"] = Start("start")
|
| 116 |
+
_open = _controllers["windows-default"].open
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# Platform support for MacOS
|
| 120 |
+
elif sys.platform == "darwin":
|
| 121 |
+
_controllers["open"] = Controller("open")
|
| 122 |
+
_open = _controllers["open"].open
|
| 123 |
+
|
| 124 |
+
# Platform support for Unix
|
| 125 |
+
else:
|
| 126 |
+
import subprocess, stat
|
| 127 |
+
|
| 128 |
+
# @WARNING: use the private API of the webbrowser module
|
| 129 |
+
# from webbrowser import _iscommand
|
| 130 |
+
|
| 131 |
+
def _isexecutable(cmd):
|
| 132 |
+
if os.path.isfile(cmd):
|
| 133 |
+
mode = os.stat(cmd)[stat.ST_MODE]
|
| 134 |
+
if mode & stat.S_IXUSR or mode & stat.S_IXGRP or mode & stat.S_IXOTH:
|
| 135 |
+
return True
|
| 136 |
+
return False
|
| 137 |
+
|
| 138 |
+
def _iscommand(cmd):
|
| 139 |
+
"""Return True if cmd is executable or can be found on the executable
|
| 140 |
+
search path."""
|
| 141 |
+
if _isexecutable(cmd):
|
| 142 |
+
return True
|
| 143 |
+
|
| 144 |
+
path = os.environ.get("PATH")
|
| 145 |
+
if not path:
|
| 146 |
+
return False
|
| 147 |
+
for d in path.split(os.pathsep):
|
| 148 |
+
exe = os.path.join(d, cmd)
|
| 149 |
+
if _isexecutable(exe):
|
| 150 |
+
return True
|
| 151 |
+
return False
|
| 152 |
+
|
| 153 |
+
class KfmClient(Controller):
|
| 154 |
+
"""Controller for the KDE kfmclient program."""
|
| 155 |
+
|
| 156 |
+
def __init__(self, kfmclient="kfmclient"):
|
| 157 |
+
super(KfmClient, self).__init__(kfmclient, "exec")
|
| 158 |
+
self.kde_version = self.detect_kde_version()
|
| 159 |
+
|
| 160 |
+
def detect_kde_version(self):
|
| 161 |
+
kde_version = None
|
| 162 |
+
try:
|
| 163 |
+
info = subprocess.getoutput("kde-config --version")
|
| 164 |
+
|
| 165 |
+
for line in info.splitlines():
|
| 166 |
+
if line.startswith("KDE"):
|
| 167 |
+
kde_version = line.split(":")[-1].strip()
|
| 168 |
+
break
|
| 169 |
+
except (OSError, RuntimeError):
|
| 170 |
+
pass
|
| 171 |
+
|
| 172 |
+
return kde_version
|
| 173 |
+
|
| 174 |
+
def fixreturncode(self, returncode):
|
| 175 |
+
if returncode is not None and self.kde_version > "3.5.4":
|
| 176 |
+
return returncode
|
| 177 |
+
else:
|
| 178 |
+
return os.EX_OK
|
| 179 |
+
|
| 180 |
+
def detect_desktop_environment():
|
| 181 |
+
"""Checks for known desktop environments
|
| 182 |
+
|
| 183 |
+
Return the desktop environments name, lowercase (kde, gnome, xfce)
|
| 184 |
+
or "generic"
|
| 185 |
+
|
| 186 |
+
"""
|
| 187 |
+
|
| 188 |
+
desktop_environment = "generic"
|
| 189 |
+
|
| 190 |
+
if os.environ.get("KDE_FULL_SESSION") == "true":
|
| 191 |
+
desktop_environment = "kde"
|
| 192 |
+
elif os.environ.get("GNOME_DESKTOP_SESSION_ID"):
|
| 193 |
+
desktop_environment = "gnome"
|
| 194 |
+
else:
|
| 195 |
+
try:
|
| 196 |
+
info = subprocess.getoutput("xprop -root _DT_SAVE_MODE")
|
| 197 |
+
if ' = "xfce4"' in info:
|
| 198 |
+
desktop_environment = "xfce"
|
| 199 |
+
except (OSError, RuntimeError):
|
| 200 |
+
pass
|
| 201 |
+
|
| 202 |
+
return desktop_environment
|
| 203 |
+
|
| 204 |
+
def register_X_controllers():
|
| 205 |
+
if _iscommand("kfmclient"):
|
| 206 |
+
_controllers["kde-open"] = KfmClient()
|
| 207 |
+
|
| 208 |
+
for command in ("gnome-open", "exo-open", "xdg-open"):
|
| 209 |
+
if _iscommand(command):
|
| 210 |
+
_controllers[command] = Controller(command)
|
| 211 |
+
|
| 212 |
+
def get():
|
| 213 |
+
controllers_map = {
|
| 214 |
+
"gnome": "gnome-open",
|
| 215 |
+
"kde": "kde-open",
|
| 216 |
+
"xfce": "exo-open",
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
desktop_environment = detect_desktop_environment()
|
| 220 |
+
|
| 221 |
+
try:
|
| 222 |
+
controller_name = controllers_map[desktop_environment]
|
| 223 |
+
return _controllers[controller_name].open
|
| 224 |
+
|
| 225 |
+
except KeyError:
|
| 226 |
+
if "xdg-open" in _controllers:
|
| 227 |
+
return _controllers["xdg-open"].open
|
| 228 |
+
else:
|
| 229 |
+
return webbrowser.open
|
| 230 |
+
|
| 231 |
+
if os.environ.get("DISPLAY"):
|
| 232 |
+
register_X_controllers()
|
| 233 |
+
_open = get()
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def open(filename):
|
| 237 |
+
"""Open a file or an URL in the registered default application."""
|
| 238 |
+
|
| 239 |
+
return _open(filename)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def _fix_addersses(**kwargs):
|
| 243 |
+
for headername in ("address", "to", "cc", "bcc"):
|
| 244 |
+
try:
|
| 245 |
+
headervalue = kwargs[headername]
|
| 246 |
+
if not headervalue:
|
| 247 |
+
del kwargs[headername]
|
| 248 |
+
continue
|
| 249 |
+
elif not isinstance(headervalue, str):
|
| 250 |
+
# assume it is a sequence
|
| 251 |
+
headervalue = ",".join(headervalue)
|
| 252 |
+
|
| 253 |
+
except KeyError:
|
| 254 |
+
pass
|
| 255 |
+
except TypeError:
|
| 256 |
+
raise TypeError(
|
| 257 |
+
'string or sequence expected for "%s", '
|
| 258 |
+
"%s found" % (headername, type(headervalue).__name__)
|
| 259 |
+
)
|
| 260 |
+
else:
|
| 261 |
+
translation_map = {"%": "%25", "&": "%26", "?": "%3F"}
|
| 262 |
+
for char, replacement in list(translation_map.items()):
|
| 263 |
+
headervalue = headervalue.replace(char, replacement)
|
| 264 |
+
kwargs[headername] = headervalue
|
| 265 |
+
|
| 266 |
+
return kwargs
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def mailto_format(**kwargs):
|
| 270 |
+
# @TODO: implement utf8 option
|
| 271 |
+
|
| 272 |
+
kwargs = _fix_addersses(**kwargs)
|
| 273 |
+
parts = []
|
| 274 |
+
for headername in ("to", "cc", "bcc", "subject", "body"):
|
| 275 |
+
if headername in kwargs:
|
| 276 |
+
headervalue = kwargs[headername]
|
| 277 |
+
if not headervalue:
|
| 278 |
+
continue
|
| 279 |
+
if headername in ("address", "to", "cc", "bcc"):
|
| 280 |
+
parts.append("%s=%s" % (headername, headervalue))
|
| 281 |
+
else:
|
| 282 |
+
headervalue = encode_rfc2231(headervalue, charset="utf-8")[
|
| 283 |
+
7:
|
| 284 |
+
] # @TODO: check
|
| 285 |
+
parts.append("%s=%s" % (headername, headervalue))
|
| 286 |
+
|
| 287 |
+
mailto_string = "mailto:%s" % kwargs.get("address", "")
|
| 288 |
+
if parts:
|
| 289 |
+
mailto_string = "%s?%s" % (mailto_string, "&".join(parts))
|
| 290 |
+
|
| 291 |
+
return mailto_string
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def mailto(address: str, to=None, cc=None, bcc=None, subject=None, body=None):
|
| 295 |
+
"""Send an e-mail using the user's preferred composer.
|
| 296 |
+
|
| 297 |
+
Open the user's preferred e-mail composer in order to send a mail to
|
| 298 |
+
address(es) that must follow the syntax of RFC822. Multiple addresses
|
| 299 |
+
may be provided (for address, cc and bcc parameters) as separate
|
| 300 |
+
arguments.
|
| 301 |
+
|
| 302 |
+
All parameters provided are used to prefill corresponding fields in
|
| 303 |
+
the user's e-mail composer. The user will have the opportunity to
|
| 304 |
+
change any of this information before actually sending the e-mail.
|
| 305 |
+
|
| 306 |
+
address - specify the destination recipient
|
| 307 |
+
cc - specify a recipient to be copied on the e-mail
|
| 308 |
+
bcc - specify a recipient to be blindly copied on the e-mail
|
| 309 |
+
subject - specify a subject for the e-mail
|
| 310 |
+
body - specify a body for the e-mail. Since the user will be able
|
| 311 |
+
to make changes before actually sending the e-mail, this
|
| 312 |
+
can be used to provide the user with a template for the
|
| 313 |
+
e-mail text may contain linebreaks
|
| 314 |
+
attach - specify an attachment for the e-mail. file must point to
|
| 315 |
+
an existing file (UNSUPPORTED)
|
| 316 |
+
|
| 317 |
+
"""
|
| 318 |
+
|
| 319 |
+
mailto_string = mailto_format(**locals())
|
| 320 |
+
return open(mailto_string)
|