mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-26 21:02:31 +03:00
f952d7a269
* feat(v2): loaders added * feature: Add scroll animations * feature: upload ui * feature: upload multiple files * fix: Same file name and size remove * feat(crawler): added * feat(parsers): v2 added more * feat(v2): audio now working * feat(v2): all loaders * feat(v2): explorer * chore: add links * feat(api): added status in return message * refactor(website): remove old code * feat(upload): return type for messages * feature: redirect to upload if ENV=local * fix(chat): fixed some issues * feature: respect response type * loading state * feature: Loading stat * feat(v2): added explore and chat pages * feature: modal settings * style: Chat UI * feature: scroll to bottom when chatting * feature: smooth scroll in chat * feature(anim): Slide chat in * feature: markdown chat * feat(explorer): list * feat(doc): added document item * feat(explore): added modal * Add clarification on Project API keys and web interface for migration scripts to Readme (#58) * fix(demo): changed link * add support to uploading zip file (#62) * Catch UnicodeEncodeError exception (#64) * feature: fixed chatbar * fix(loaders): missing argument * fix: layout * fix: One whole chatbox * fix: Scroll into view * fix(build): vercel issues * chore(streamlit): moved to own file * refactor(api): moved to backend folder * feat(docker): added docker compose * Fix a bug where langchain memories were not being cleaned (#71) * Update README.md (#70) * chore(streamlit): moved to own file * refactor(api): moved to backend folder * docs(readme): updated for new version * docs(readme): added old readme * docs(readme): update copy dot env file * docs(readme): cleanup --------- Co-authored-by: iMADi-ARCH <nandanaditya985@gmail.com> Co-authored-by: Matt LeBel <github@lebel.io> Co-authored-by: Evan Carlson <45178375+EvanCarlson@users.noreply.github.com> Co-authored-by: Mustafa Hasan Khan <65130881+mustafahasankhan@users.noreply.github.com> Co-authored-by: zhulixi <48713110+zlxxlz1026@users.noreply.github.com> Co-authored-by: Stanisław Tuszyński <stanislaw@tuszynski.me>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from .common import process_file
|
|
from langchain.document_loaders import UnstructuredHTMLLoader
|
|
import requests
|
|
import re
|
|
import unicodedata
|
|
import tempfile
|
|
import os
|
|
import streamlit as st
|
|
from streamlit.runtime.uploaded_file_manager import UploadedFileRec, UploadedFile
|
|
|
|
def process_html(vector_store, file, stats_db):
|
|
return process_file(vector_store, file, UnstructuredHTMLLoader, ".html", stats_db=stats_db)
|
|
|
|
|
|
def get_html(url):
|
|
response = requests.get(url)
|
|
if response.status_code == 200:
|
|
return response.text
|
|
else:
|
|
return None
|
|
|
|
def create_html_file(url, content):
|
|
file_name = slugify(url) + ".html"
|
|
temp_file_path = os.path.join(tempfile.gettempdir(), file_name)
|
|
with open(temp_file_path, 'w') as temp_file:
|
|
temp_file.write(content)
|
|
|
|
record = UploadedFileRec(id=None, name=file_name, type='text/html', data=open(temp_file_path, 'rb').read())
|
|
uploaded_file = UploadedFile(record)
|
|
|
|
return uploaded_file, temp_file_path
|
|
|
|
def delete_tempfile(temp_file_path, url, ret):
|
|
try:
|
|
os.remove(temp_file_path)
|
|
if ret:
|
|
st.write(f"✅ Content saved... {url} ")
|
|
except OSError as e:
|
|
print(f"Error while deleting the temporary file: {str(e)}")
|
|
if ret:
|
|
st.write(f"❌ Error while saving content... {url} ")
|
|
|
|
def slugify(text):
|
|
text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('utf-8')
|
|
text = re.sub(r'[^\w\s-]', '', text).strip().lower()
|
|
text = re.sub(r'[-\s]+', '-', text)
|
|
return text |