monusurana commited on
Commit
ee8f394
·
1 Parent(s): 8ac93b8

Deployed RAG based IMDB Movie Chat bot

Browse files

- Added requirements.txt and chainlit application
- Move vector databased on LFS
- Update permissions for app
- Added gradio_client to fix Exception in ASGI application
- Updated welcome screen and added support for generic questions for chat

.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ app/faiss_index/index.faiss filter=lfs diff=lfs merge=lfs -text
37
+ app/faiss_index/index.pkl filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN useradd -m -u 1000 user
10
+ USER user
11
+ ENV HOME=/home/user \
12
+ PATH=/home/user/.local/bin:$PATH
13
+
14
+ WORKDIR $HOME/app
15
+
16
+ RUN chown -R user:user $HOME/app
17
+
18
+ ADD app $HOME/app
19
+
20
+ CMD ["chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
app/app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_openai import ChatOpenAI
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.schema import StrOutputParser
4
+ from langchain.schema.runnable import Runnable
5
+ from langchain.schema.runnable.config import RunnableConfig
6
+ from langchain_community.vectorstores import FAISS
7
+ from langchain_openai import OpenAIEmbeddings
8
+ import chainlit as cl
9
+
10
+
11
+ @cl.on_chat_start
12
+ async def on_chat_start():
13
+ embedding_model = OpenAIEmbeddings(model="text-embedding-3-small")
14
+ vector_store = FAISS.load_local("/home/user/app/faiss_index", embedding_model, allow_dangerous_deserialization=True)
15
+ retriever = vector_store.as_retriever()
16
+
17
+ prompt_template = PromptTemplate.from_template("{question}")
18
+ chat_model = ChatOpenAI(streaming=True)
19
+
20
+ runnable = retriever | prompt_template | chat_model | StrOutputParser()
21
+ cl.user_session.set("runnable", runnable)
22
+
23
+
24
+ @cl.on_message
25
+ async def on_message(message: cl.Message):
26
+ runnable = cl.user_session.get("runnable") # type: Runnable
27
+
28
+ msg = cl.Message(content="")
29
+
30
+ async for chunk in runnable.astream(
31
+ message.content,
32
+ config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
33
+ ):
34
+ await msg.stream_token(chunk)
35
+
36
+ await msg.send()
app/chainlit.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Welcome to IMDB Movie Bot Chat!
2
+
3
+ Welcome to IMDB Movie Bot Chat, where you can explore the fascinating world of movies and television! Whether you're a casual movie enthusiast or a dedicated film buff, this is the perfect place to discover new favorites, discuss classics, and delve into the latest releases.
4
+
5
+ ## What Can You Do Here?
6
+
7
+ - **Search Movies**: Looking for information about a specific movie? Just type its title, and IMDB Movie Bot will provide you with details such as cast, plot summary, ratings, and more!
8
+
9
+ - **Discover Recommendations**: Need some recommendations for what to watch next? Tell us your preferences, and we'll suggest movies tailored just for you.
10
+
11
+ - **Discuss Favorites**: Have a favorite movie you can't stop talking about? Share it with the community and engage in lively discussions about what makes it special.
12
+
13
+ ## How to Get Started?
14
+
15
+ Getting started is easy! Simply type your query or command in the chatbox, and IMDB Movie Bot will do the rest. Whether you're here to search for a specific movie, chat with fellow movie buffs, or simply explore, we're excited to have you join us.
16
+
17
+ So, sit back, grab some popcorn, and let's embark on a cinematic journey together at IMDB Movie Bot Chat! 🍿🎬
app/faiss_index/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d877e002b0a0d0f693a198c213d6b6a8f968d9f673e25e56ad769f7e91d8077
3
+ size 117209133
app/faiss_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:24fef3b32957ca271046114ed5d122ac3d0ba37cf05830cfddb3e1a363f026d2
3
+ size 13356445
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ chainlit==1.1.101
2
+ datasets==2.19.1
3
+ faiss-cpu==1.8.0
4
+ langchain==0.2.0
5
+ langchain-community==0.2.0
6
+ langchain-openai==0.1.7
7
+ tiktoken==0.7.0
8
+ gradio_client