Spaces:
Runtime error
Runtime error
Commit
Β·
9bbd1a7
1
Parent(s):
3dd1db2
Upload 4 files
Browse files- Dockerfile +11 -0
- app.py +74 -0
- chainlit.md +14 -0
- requirements.txt +16 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10
|
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"]
|
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chainlit as cl
|
2 |
+
import asyncio
|
3 |
+
import wandb
|
4 |
+
import pandas as pd
|
5 |
+
import pinecone
|
6 |
+
import os
|
7 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
8 |
+
from langchain.embeddings import CacheBackedEmbeddings
|
9 |
+
from langchain.storage import LocalFileStore
|
10 |
+
from langchain.vectorstores import Pinecone
|
11 |
+
from langchain.chains import RetrievalQA
|
12 |
+
from langchain.callbacks import StdOutCallbackHandler
|
13 |
+
from langchain.chat_models import ChatOpenAI
|
14 |
+
import langchain
|
15 |
+
from langchain.cache import InMemoryCache
|
16 |
+
|
17 |
+
pinecone.init(
|
18 |
+
api_key= os.environ['PINECONE_API_KEY'],
|
19 |
+
environment= os.environ['PINECONE_ENV']
|
20 |
+
)
|
21 |
+
|
22 |
+
index_name = 'movie-review-index'
|
23 |
+
index = pinecone.Index(index_name)
|
24 |
+
|
25 |
+
|
26 |
+
@cl.on_chat_start
|
27 |
+
async def on_chat_start():
|
28 |
+
|
29 |
+
msg = cl.Message(
|
30 |
+
content=f"Loading Dataset ...", disable_human_feedback=True
|
31 |
+
)
|
32 |
+
await msg.send()
|
33 |
+
|
34 |
+
text_field = "text"
|
35 |
+
|
36 |
+
store = LocalFileStore("./cache/")
|
37 |
+
|
38 |
+
core_embeddings_model = OpenAIEmbeddings()
|
39 |
+
embedder = CacheBackedEmbeddings.from_bytes_store(
|
40 |
+
core_embeddings_model,
|
41 |
+
store,
|
42 |
+
namespace= core_embeddings_model.model
|
43 |
+
)
|
44 |
+
vectorstore = Pinecone(
|
45 |
+
index, embedder.embed_query, text_field
|
46 |
+
)
|
47 |
+
# docsearch = Pinecone.from_existing_index(
|
48 |
+
# index_name=index_name, embedding=embedder.embed_query, namespace=None
|
49 |
+
# )
|
50 |
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
51 |
+
retriever = vectorstore.as_retriever()
|
52 |
+
handler = StdOutCallbackHandler()
|
53 |
+
|
54 |
+
qa_with_sources_chain = RetrievalQA.from_chain_type(
|
55 |
+
llm=llm,
|
56 |
+
retriever=retriever,
|
57 |
+
callbacks=[handler],
|
58 |
+
return_source_documents=True
|
59 |
+
)
|
60 |
+
langchain.llm_cache = InMemoryCache()
|
61 |
+
# Let the user know that the system is ready
|
62 |
+
msg.content = f"Dataset loading is done. You can now ask questions!"
|
63 |
+
await msg.update()
|
64 |
+
|
65 |
+
cl.user_session.set("chain", qa_with_sources_chain)
|
66 |
+
|
67 |
+
@cl.on_message
|
68 |
+
async def main(message:str):
|
69 |
+
chain = cl.user_session.get("chain")
|
70 |
+
output = chain({"query":message})
|
71 |
+
# print(output)
|
72 |
+
msg = cl.Message(content=f"{output['result']}")
|
73 |
+
# msg.prompt = output
|
74 |
+
await msg.send()
|
chainlit.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Welcome to Chainlit! ππ€
|
2 |
+
|
3 |
+
Hi there, Developer! π We're excited to have you on board. Chainlit is a powerful tool designed to help you prototype, debug and share applications built on top of LLMs.
|
4 |
+
|
5 |
+
## Useful Links π
|
6 |
+
|
7 |
+
- **Documentation:** Get started with our comprehensive [Chainlit Documentation](https://docs.chainlit.io) π
|
8 |
+
- **Discord Community:** Join our friendly [Chainlit Discord](https://discord.gg/k73SQ3FyUh) to ask questions, share your projects, and connect with other developers! π¬
|
9 |
+
|
10 |
+
We can't wait to see what you create with Chainlit! Happy coding! π»π
|
11 |
+
|
12 |
+
## Welcome screen
|
13 |
+
|
14 |
+
To modify the welcome screen, edit the `chainlit.md` file at the root of your project. If you do not want a welcome screen, just leave this file empty.
|
requirements.txt
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
requests
|
2 |
+
scrapy
|
3 |
+
selenium
|
4 |
+
numpy==1.25.2
|
5 |
+
openai==0.27.8
|
6 |
+
python-dotenv==1.0.0
|
7 |
+
pandas
|
8 |
+
scikit-learn
|
9 |
+
ipykernel
|
10 |
+
matplotlib
|
11 |
+
plotly
|
12 |
+
wandb
|
13 |
+
chainlit
|
14 |
+
pinecone-client[grpc]
|
15 |
+
tiktoken
|
16 |
+
langchain
|