Update utils.py
Browse files
utils.py
CHANGED
@@ -1,3 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
################################################
|
2 |
#Pfad, wo Docs/Bilder/Filme abgelegt werden können - lokal, also hier im HF Space (sonst auf eigenem Rechner)
|
3 |
PATH_WORK = "."
|
|
|
1 |
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Tuple, Type
|
2 |
+
import logging
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
from datetime import datetime
|
6 |
+
import hashlib
|
7 |
+
import csv
|
8 |
+
import requests
|
9 |
+
import re
|
10 |
+
import html
|
11 |
+
import markdown2
|
12 |
+
import torch
|
13 |
+
import sys
|
14 |
+
import gc
|
15 |
+
from pygments.lexers import guess_lexer, ClassNotFound
|
16 |
+
import time
|
17 |
+
import json
|
18 |
+
import operator
|
19 |
+
from typing import Annotated, Sequence, TypedDict
|
20 |
+
import pprint
|
21 |
+
|
22 |
+
import gradio as gr
|
23 |
+
from pypinyin import lazy_pinyin
|
24 |
+
import tiktoken
|
25 |
+
import mdtex2html
|
26 |
+
from markdown import markdown
|
27 |
+
from pygments import highlight
|
28 |
+
from pygments.lexers import guess_lexer,get_lexer_by_name
|
29 |
+
from pygments.formatters import HtmlFormatter
|
30 |
+
|
31 |
+
from langchain.chains import LLMChain, RetrievalQA
|
32 |
+
from langgraph.graph import END, StateGraph
|
33 |
+
from langchain_openai import ChatOpenAI
|
34 |
+
from langchain_community.document_loaders import PyPDFLoader, WebBaseLoader, UnstructuredWordDocumentLoader, DirectoryLoader
|
35 |
+
from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
|
36 |
+
from langchain.document_loaders.generic import GenericLoader
|
37 |
+
from langchain.document_loaders.parsers import OpenAIWhisperParser
|
38 |
+
from langchain.schema import AIMessage, HumanMessage
|
39 |
+
from langchain_community.llms import HuggingFaceHub
|
40 |
+
from langchain_community.llms import HuggingFaceTextGenInference
|
41 |
+
from langchain_community.embeddings import HuggingFaceInstructEmbeddings, HuggingFaceEmbeddings, HuggingFaceBgeEmbeddings, HuggingFaceInferenceAPIEmbeddings
|
42 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
43 |
+
from langchain.retrievers.tavily_search_api import TavilySearchAPIRetriever
|
44 |
+
from typing import Dict, TypedDict
|
45 |
+
from langchain_core.messages import BaseMessage
|
46 |
+
from langchain_openai import OpenAIEmbeddings
|
47 |
+
from langchain.prompts import PromptTemplate
|
48 |
+
|
49 |
+
|
50 |
+
from langchain import hub
|
51 |
+
from langchain.output_parsers.openai_tools import PydanticToolsParser
|
52 |
+
from langchain.prompts import PromptTemplate
|
53 |
+
from langchain.schema import Document
|
54 |
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
55 |
+
from langchain_community.vectorstores import Chroma
|
56 |
+
from langchain_core.messages import BaseMessage, FunctionMessage
|
57 |
+
from langchain_core.output_parsers import StrOutputParser
|
58 |
+
from langchain_core.pydantic_v1 import BaseModel, Field
|
59 |
+
from langchain_core.runnables import RunnablePassthrough
|
60 |
+
from langchain_core.utils.function_calling import convert_to_openai_tool
|
61 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
62 |
+
from langchain_community.vectorstores import Chroma
|
63 |
+
from chromadb.errors import InvalidDimensionException
|
64 |
+
import io
|
65 |
+
from PIL import Image, ImageDraw, ImageOps, ImageFont
|
66 |
+
import base64
|
67 |
+
from tempfile import NamedTemporaryFile
|
68 |
+
|
69 |
+
import nltk
|
70 |
+
from nltk.corpus import stopwords
|
71 |
+
from nltk.tokenize import word_tokenize
|
72 |
+
from nltk.stem import WordNetLemmatizer
|
73 |
+
nltk.download('punkt')
|
74 |
+
|
75 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
76 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
77 |
+
import numpy as np
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
################################################
|
82 |
#Pfad, wo Docs/Bilder/Filme abgelegt werden können - lokal, also hier im HF Space (sonst auf eigenem Rechner)
|
83 |
PATH_WORK = "."
|