Update filetypes

Rene Teigen 2 years ago
parent 0555cf8b33
commit 64ce627bb7

@ -29,7 +29,14 @@ class Index_handler:
try: try:
temp_path = tempfile.TemporaryDirectory() temp_path = tempfile.TemporaryDirectory()
temp_file = tempfile.NamedTemporaryFile(suffix=".txt", dir=temp_path.name, delete=False) if file.content_type.startswith("text/plain"):
suffix = ".txt"
elif file.content_type.startswith("application/pdf"):
suffix = ".pdf"
else:
await ctx.respond("Only accepts txt or pdf files")
return
temp_file = tempfile.NamedTemporaryFile(suffix=suffix, dir=temp_path.name, delete=False)
await file.save(temp_file.name) await file.save(temp_file.name)
index = await self.loop.run_in_executor(None, partial(self.index_file, temp_path.name)) index = await self.loop.run_in_executor(None, partial(self.index_file, temp_path.name))
self.index_storage[ctx.user.id] = index self.index_storage[ctx.user.id] = index

@ -32,6 +32,7 @@ dependencies = [
"flask", "flask",
"beautifulsoup4", "beautifulsoup4",
"gpt-index", "gpt-index",
"PyPDF2",
] ]
dynamic = ["version"] dynamic = ["version"]
[project.scripts] [project.scripts]

@ -11,3 +11,4 @@ backoff==2.2.1
flask==2.2.2 flask==2.2.2
beautifulsoup4==4.11.1 beautifulsoup4==4.11.1
gpt-index==0.2.16 gpt-index==0.2.16
PyPDF2==3.0.1
Loading…
Cancel
Save