danicafisher commited on
Commit
712a5c6
·
0 Parent(s):

Starts hugging face

Browse files
Files changed (6) hide show
  1. Dockerfile +11 -0
  2. Marketing-Content-Enhancer +1 -0
  3. app.py +88 -0
  4. chainlit.md +5 -0
  5. helpers.py +14 -0
  6. requirements.txt +132 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ RUN useradd -m -u 1000 user
3
+ USER user
4
+ ENV HOME=/home/user \
5
+ PATH=/home/user/.local/bin:$PATH
6
+ WORKDIR $HOME/app
7
+ COPY --chown=user . $HOME/app
8
+ COPY ./requirements.txt ~/app/requirements.txt
9
+ RUN pip install -r requirements.txt
10
+ COPY . .
11
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
Marketing-Content-Enhancer ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit ad6d1af3d79805ce35ae2ef7fa315292af88ad31
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import chainlit as cl
3
+ from dotenv import load_dotenv
4
+ from operator import itemgetter
5
+ from langchain_community.vectorstores import Qdrant
6
+ from langchain_openai.chat_models import ChatOpenAI
7
+ from langchain_text_splitters import RecursiveCharacterTextSplitter
8
+ from langchain.prompts import ChatPromptTemplate
9
+ from langchain.schema.output_parser import StrOutputParser
10
+ from helpers import process_file
11
+
12
+
13
+ # ---- ENV VARIABLES ---- #
14
+ load_dotenv()
15
+ # HF_LLM_ENDPOINT = os.environ["HF_LLM_ENDPOINT"]
16
+ # HF_EMBED_ENDPOINT = os.environ["HF_EMBED_ENDPOINT"]
17
+ # HF_TOKEN = os.environ["HF_TOKEN"]
18
+
19
+
20
+ # -- RETRIEVAL -- #
21
+ # TO DO: Process file based on type (PDF, TXT, etc.)
22
+ embedding = HuggingFaceEndpointEmbeddings() # TO DO: Add embeddings
23
+ vectorstore = Qdrant.from_documents() # TO DO: Add vector store
24
+ retriever = vectorstore.as_retriever() # TO DO: Add retriever
25
+
26
+ # -- AUGMENTED -- #
27
+ RAG_PROMPT_TEMPLATE = """\
28
+ <|start_header_id|>system<|end_header_id|>
29
+ You are a helpful assistant. You answer user questions based on provided context. If you can't answer the question with the provided context, say you don't know.<|eot_id|>
30
+ <|start_header_id|>user<|end_header_id|>
31
+ User Query:
32
+ {query}
33
+ Context:
34
+ {context}<|eot_id|>
35
+ <|start_header_id|>assistant<|end_header_id|>
36
+ """
37
+
38
+ rag_prompt = ChatPromptTemplate.from_template(RAG_PROMPT_TEMPLATE)
39
+
40
+ # -- GENERATION -- #
41
+ llm = ChatOpenAI(model="gpt-4")
42
+
43
+ ### On Chat Start (Session Start) Section ###
44
+ @cl.on_chat_start
45
+ async def on_chat_start():
46
+ files = None
47
+
48
+ # Wait for the user to upload a file
49
+ while files == None:
50
+ files = await cl.AskFileMessage(
51
+ content="Please ask a question or upload a Text or PDF File file to begin!",
52
+ accept=["text/plain", "application/pdf"],
53
+ max_size_mb=2,
54
+ timeout=180,
55
+ ).send()
56
+
57
+ file = files[0]
58
+
59
+ msg = cl.Message(
60
+ content=f"Processing `{file.name}`...", disable_human_feedback=True
61
+ )
62
+ await msg.send()
63
+
64
+ # load the file
65
+ docs = process_file(file)
66
+ for i, doc in enumerate(docs):
67
+ doc.metadata["source"] = f"source_{i}" # TO DO: Add metadata
68
+
69
+ print(f"Processing {len(docs)} text chunks")
70
+
71
+ # Create a chain
72
+ rag_chain = (
73
+ {"context": itemgetter("question") | retriever, "question": itemgetter("question")}
74
+ | rag_prompt | llm | StrOutputParser()
75
+ )
76
+
77
+ # Let the user know that the system is ready
78
+ msg.content = f"Processing `{file.name}` done. You can now ask questions!"
79
+ await msg.update()
80
+ cl.user_session.set("chain", rag_chain)
81
+
82
+ @cl.on_message
83
+ async def main(message: cl.Message):
84
+ chain = cl.user_session.get("chain")
85
+ result = chain.invoke({"question":message.content})
86
+ msg = cl.Message(content=result)
87
+
88
+ await msg.send()
chainlit.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Marketing Content Enhancer
2
+
3
+ The Marketing Content Enhancer is an AI-powered platform that uses a team of specialized agents to gather, verify, and present information in a clear, tone-sensitive manner. It allows users to easily add new resources while ensuring accuracy and relevance, with future capabilities including visual content generation and scalable deployment.
4
+
5
+ Start by asking a question or uploading a file.
helpers.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.document_loaders import PyMuPDFLoader, TextLoader
2
+
3
+
4
+ def process_file(file):
5
+ documents = []
6
+ if file.endswith(".pdf"):
7
+ loader = PyMuPDFLoader(file)
8
+ docs = loader.load()
9
+ documents.extend(docs)
10
+ else:
11
+ loader = TextLoader(file)
12
+ docs = loader.load()
13
+ documents.extend(docs)
14
+ return documents
requirements.txt ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ aiohappyeyeballs==2.4.3
3
+ aiohttp==3.10.8
4
+ aiosignal==1.3.1
5
+ annotated-types==0.7.0
6
+ anyio==3.7.1
7
+ async-timeout==4.0.3
8
+ asyncer==0.0.2
9
+ attrs==24.2.0
10
+ bidict==0.23.1
11
+ certifi==2024.8.30
12
+ chainlit==0.7.700
13
+ charset-normalizer==3.3.2
14
+ click==8.1.7
15
+ dataclasses-json==0.5.14
16
+ Deprecated==1.2.14
17
+ distro==1.9.0
18
+ exceptiongroup==1.2.2
19
+ faiss-cpu==1.8.0.post1
20
+ fastapi==0.100.1
21
+ fastapi-socketio==0.0.10
22
+ filelock==3.16.1
23
+ filetype==1.2.0
24
+ frozenlist==1.4.1
25
+ fsspec==2024.9.0
26
+ googleapis-common-protos==1.65.0
27
+ greenlet==3.1.1
28
+ grpcio==1.66.2
29
+ grpcio-tools==1.62.3
30
+ h11==0.14.0
31
+ h2==4.1.0
32
+ hpack==4.0.0
33
+ httpcore==0.17.3
34
+ httpx==0.24.1
35
+ huggingface-hub==0.25.1
36
+ hyperframe==6.0.1
37
+ idna==3.10
38
+ importlib_metadata==8.4.0
39
+ Jinja2==3.1.4
40
+ jiter==0.5.0
41
+ joblib==1.4.2
42
+ jsonpatch==1.33
43
+ jsonpointer==3.0.0
44
+ langchain==0.3.0
45
+ langchain-community==0.3.0
46
+ langchain-core==0.3.1
47
+ langchain-huggingface==0.1.0
48
+ langchain-openai==0.2.0
49
+ langchain-qdrant==0.1.4
50
+ langchain-text-splitters==0.3.0
51
+ langsmith==0.1.121
52
+ Lazify==0.4.0
53
+ MarkupSafe==2.1.5
54
+ marshmallow==3.22.0
55
+ mpmath==1.3.0
56
+ multidict==6.1.0
57
+ mypy-extensions==1.0.0
58
+ nest-asyncio==1.6.0
59
+ networkx==3.2.1
60
+ numpy==1.26.4
61
+ nvidia-cublas-cu12==12.1.3.1
62
+ nvidia-cuda-cupti-cu12==12.1.105
63
+ nvidia-cuda-nvrtc-cu12==12.1.105
64
+ nvidia-cuda-runtime-cu12==12.1.105
65
+ nvidia-cudnn-cu12==9.1.0.70
66
+ nvidia-cufft-cu12==11.0.2.54
67
+ nvidia-curand-cu12==10.3.2.106
68
+ nvidia-cusolver-cu12==11.4.5.107
69
+ nvidia-cusparse-cu12==12.1.0.106
70
+ nvidia-nccl-cu12==2.20.5
71
+ nvidia-nvjitlink-cu12==12.6.77
72
+ nvidia-nvtx-cu12==12.1.105
73
+ openai==1.51.0
74
+ opentelemetry-api==1.27.0
75
+ opentelemetry-exporter-otlp==1.27.0
76
+ opentelemetry-exporter-otlp-proto-common==1.27.0
77
+ opentelemetry-exporter-otlp-proto-grpc==1.27.0
78
+ opentelemetry-exporter-otlp-proto-http==1.27.0
79
+ opentelemetry-instrumentation==0.48b0
80
+ opentelemetry-proto==1.27.0
81
+ opentelemetry-sdk==1.27.0
82
+ opentelemetry-semantic-conventions==0.48b0
83
+ orjson==3.10.7
84
+ packaging==23.2
85
+ pillow==10.4.0
86
+ portalocker==2.10.1
87
+ protobuf==4.25.5
88
+ pydantic==2.9.2
89
+ pydantic-settings==2.5.2
90
+ pydantic_core==2.23.4
91
+ PyJWT==2.9.0
92
+ PyMuPDF==1.24.10
93
+ PyMuPDFb==1.24.10
94
+ python-dotenv==1.0.1
95
+ python-engineio==4.9.1
96
+ python-graphql-client==0.4.3
97
+ python-multipart==0.0.6
98
+ python-socketio==5.11.4
99
+ PyYAML==6.0.2
100
+ qdrant-client==1.11.2
101
+ regex==2024.9.11
102
+ requests==2.32.3
103
+ safetensors==0.4.5
104
+ scikit-learn==1.5.2
105
+ scipy==1.13.1
106
+ sentence-transformers==3.1.1
107
+ simple-websocket==1.0.0
108
+ sniffio==1.3.1
109
+ SQLAlchemy==2.0.35
110
+ starlette==0.27.0
111
+ sympy==1.13.3
112
+ syncer==2.0.3
113
+ tenacity==8.5.0
114
+ threadpoolctl==3.5.0
115
+ tiktoken==0.7.0
116
+ tokenizers==0.20.0
117
+ tomli==2.0.1
118
+ torch==2.4.1
119
+ tqdm==4.66.5
120
+ transformers==4.45.1
121
+ triton==3.0.0
122
+ typing-inspect==0.9.0
123
+ typing_extensions==4.12.2
124
+ uptrace==1.26.0
125
+ urllib3==2.2.3
126
+ uvicorn==0.23.2
127
+ watchfiles==0.20.0
128
+ websockets==13.1
129
+ wrapt==1.16.0
130
+ wsproto==1.2.0
131
+ yarl==1.13.1
132
+ zipp==3.20.2