Update utils.py
Browse files
utils.py
CHANGED
@@ -19,6 +19,7 @@ import json
|
|
19 |
import base64
|
20 |
from io import BytesIO
|
21 |
import urllib.parse
|
|
|
22 |
import tempfile
|
23 |
import uuid
|
24 |
|
@@ -747,8 +748,6 @@ def rag_chain_simpel( prompt, retriever):
|
|
747 |
#passend zum Prompt relevante Dokuemnte raussuchen
|
748 |
relevant_docs = retriever.invoke(prompt)
|
749 |
|
750 |
-
print("relevant docs............."+str(relevant_docs))
|
751 |
-
|
752 |
#zu jedem relevanten Dokument die wichtigen Informationen zusammenstellen (im Dict)
|
753 |
extracted_docs = extract_document_info(relevant_docs)
|
754 |
|
@@ -869,6 +868,7 @@ def transfer_input(inputs):
|
|
869 |
|
870 |
########################################################
|
871 |
######## Hilfsfunktionen Datei-Upload ##################
|
|
|
872 |
def download_link(doc):
|
873 |
# URL für das Herunterladen der Datei
|
874 |
# Check if doc is a dictionary and contains the key 'pfad'
|
@@ -878,6 +878,23 @@ def download_link(doc):
|
|
878 |
else:
|
879 |
file_url = f"https://huggingface.co/spaces/alexkueck/SucheRAG/resolve/main/{doc}?token=hf_token"
|
880 |
return f'<b><a href="{file_url}" target="_blank" style="color: #BB70FC; font-weight: bold;">{doc}</a></b>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
881 |
|
882 |
|
883 |
|
|
|
19 |
import base64
|
20 |
from io import BytesIO
|
21 |
import urllib.parse
|
22 |
+
from urllib.parse import quote
|
23 |
import tempfile
|
24 |
import uuid
|
25 |
|
|
|
748 |
#passend zum Prompt relevante Dokuemnte raussuchen
|
749 |
relevant_docs = retriever.invoke(prompt)
|
750 |
|
|
|
|
|
751 |
#zu jedem relevanten Dokument die wichtigen Informationen zusammenstellen (im Dict)
|
752 |
extracted_docs = extract_document_info(relevant_docs)
|
753 |
|
|
|
868 |
|
869 |
########################################################
|
870 |
######## Hilfsfunktionen Datei-Upload ##################
|
871 |
+
"""
|
872 |
def download_link(doc):
|
873 |
# URL für das Herunterladen der Datei
|
874 |
# Check if doc is a dictionary and contains the key 'pfad'
|
|
|
878 |
else:
|
879 |
file_url = f"https://huggingface.co/spaces/alexkueck/SucheRAG/resolve/main/{doc}?token=hf_token"
|
880 |
return f'<b><a href="{file_url}" target="_blank" style="color: #BB70FC; font-weight: bold;">{doc}</a></b>'
|
881 |
+
"""
|
882 |
+
|
883 |
+
def download_link(doc):
|
884 |
+
# Basis-URL für das Hugging Face Repository
|
885 |
+
base_url = f"https://huggingface.co/spaces/{STORAGE_REPO_ID}/resolve/main"
|
886 |
+
|
887 |
+
# Check if doc is a dictionary and contains the key 'pfad'
|
888 |
+
if isinstance(doc, dict) and 'pfad' in doc:
|
889 |
+
# URL-encode the path to handle special characters
|
890 |
+
encoded_path = quote(doc['pfad'])
|
891 |
+
file_url = f"{base_url}/{encoded_path}?token={hf_token}"
|
892 |
+
return f'<b><a href="{file_url}" target="_blank" style="color: #BB70FC; font-weight: bold;">{doc["titel"]}</a></b>'
|
893 |
+
else:
|
894 |
+
# URL-encode the document name to handle special characters
|
895 |
+
encoded_doc = quote(doc)
|
896 |
+
file_url = f"{base_url}/{encoded_doc}?token={hf_token}"
|
897 |
+
return f'<b><a href="{file_url}" target="_blank" style="color: #BB70FC; font-weight: bold;">{doc}</a></b>'
|
898 |
|
899 |
|
900 |
|