captain-awesome commited on
Commit
96d88aa
1 Parent(s): c799424

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.chains import ConversationalRetrievalChain
2
+ from langchain.chains.question_answering import load_qa_chain
3
+ from langchain.chains import RetrievalQA
4
+ from langchain.memory import ConversationBufferMemory
5
+ from langchain.memory import ConversationTokenBufferMemory
6
+ from langchain.llms import HuggingFacePipeline
7
+ # from langchain import PromptTemplate
8
+ from langchain.prompts import PromptTemplate
9
+ from langchain.embeddings import HuggingFaceEmbeddings
10
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
11
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
12
+ from langchain.vectorstores import Chroma
13
+ from langchain.embeddings import HuggingFaceBgeEmbeddings
14
+ from langchain.document_loaders import (
15
+ CSVLoader,
16
+ DirectoryLoader,
17
+ GitLoader,
18
+ NotebookLoader,
19
+ OnlinePDFLoader,
20
+ PythonLoader,
21
+ TextLoader,
22
+ UnstructuredFileLoader,
23
+ UnstructuredHTMLLoader,
24
+ UnstructuredPDFLoader,
25
+ UnstructuredWordDocumentLoader,
26
+ WebBaseLoader,
27
+ PyPDFLoader,
28
+ UnstructuredMarkdownLoader,
29
+ UnstructuredEPubLoader,
30
+ UnstructuredHTMLLoader,
31
+ UnstructuredPowerPointLoader,
32
+ UnstructuredODTLoader,
33
+ NotebookLoader,
34
+ UnstructuredFileLoader
35
+ )
36
+ from transformers import (
37
+ AutoModelForCausalLM,
38
+ AutoTokenizer,
39
+ StoppingCriteria,
40
+ StoppingCriteriaList,
41
+ pipeline,
42
+ GenerationConfig,
43
+ TextStreamer,
44
+ pipeline
45
+ )
46
+ from langchain.llms import HuggingFaceHub
47
+ import torch
48
+ from transformers import BitsAndBytesConfig
49
+ import os
50
+ from langchain.llms import CTransformers
51
+ import streamlit as st
52
+ from langchain.document_loaders.base import BaseLoader
53
+ from langchain.schema import Document
54
+ import gradio as gr
55
+ import tempfile
56
+ import timeit
57
+
58
+ FILE_LOADER_MAPPING = {
59
+ "csv": (CSVLoader, {"encoding": "utf-8"}),
60
+ "doc": (UnstructuredWordDocumentLoader, {}),
61
+ "docx": (UnstructuredWordDocumentLoader, {}),
62
+ "epub": (UnstructuredEPubLoader, {}),
63
+ "html": (UnstructuredHTMLLoader, {}),
64
+ "md": (UnstructuredMarkdownLoader, {}),
65
+ "odt": (UnstructuredODTLoader, {}),
66
+ "pdf": (PyPDFLoader, {}),
67
+ "ppt": (UnstructuredPowerPointLoader, {}),
68
+ "pptx": (UnstructuredPowerPointLoader, {}),
69
+ "txt": (TextLoader, {"encoding": "utf8"}),
70
+ "ipynb": (NotebookLoader, {}),
71
+ "py": (PythonLoader, {}),
72
+ # Add more mappings for other file extensions and loaders as needed
73
+ }
74
+
75
+ def load_model():
76
+ config = {'max_new_tokens': 1024,
77
+ 'repetition_penalty': 1.1,
78
+ 'temperature': 0.1,
79
+ 'top_k': 50,
80
+ 'top_p': 0.9,
81
+ 'stream': True,
82
+ 'threads': int(os.cpu_count() / 2)
83
+ }
84
+
85
+ llm = CTransformers(
86
+ model = "TheBloke/zephyr-7B-beta-GGUF",
87
+ model_file = "zephyr-7b-beta.Q4_0.gguf",
88
+ callbacks=[StreamingStdOutCallbackHandler()],
89
+ lib="avx2", #for CPU use
90
+ **config
91
+ # model_type=model_type,
92
+ # max_new_tokens=max_new_tokens, # type: ignore
93
+ # temperature=temperature, # type: ignore
94
+ )
95
+ return llm