-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
333 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flagged/ | ||
scripts/__pycache__ | ||
docker/build_command.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.10-slim-buster | ||
|
||
# Set the working directory in the container to /app | ||
WORKDIR /app | ||
|
||
# Add the current directory contents into the container at /app | ||
ADD . /app | ||
|
||
# Update and install system dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
libpq-dev \ | ||
libffi-dev \ | ||
libssl-dev \ | ||
musl-dev \ | ||
libxml2-dev \ | ||
libxslt1-dev \ | ||
zlib1g-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Python dependencies | ||
RUN python3 -m pip cache purge | ||
RUN python3 -m pip install --no-cache-dir -r requirements.txt | ||
|
||
# Set version | ||
ARG version="v0.1.0" | ||
|
||
# Echo version | ||
RUN echo "Started everything-rag ${version}" | ||
|
||
# Set default model and task | ||
ENV model="google/flan-t5-base" | ||
|
||
ENV task="text2text-generation" | ||
|
||
# Run script to install and build the model for the first time | ||
RUN python3 utils.py -m ${model} -t ${task} | ||
|
||
# Expose the port that the application will run on | ||
EXPOSE 7860 | ||
|
||
# Set the entrypoint with a default command and allow the user to override it | ||
ENTRYPOINT ["python3", "chat.py", "-m", "${model}", "-t", "${task}"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import gradio as gr | ||
import os | ||
import time | ||
from utils import * | ||
|
||
vectordb = "" | ||
|
||
def generate_welcome_message(): | ||
return (None, "Hello! Welcome to the chatbot. You can enter a message or upload a file.") | ||
|
||
def print_like_dislike(x: gr.LikeData): | ||
print(x.index, x.value, x.liked) | ||
|
||
def add_message(history, message): | ||
if len(message["files"]) > 0: | ||
history.append((message["files"], None)) | ||
if message["text"] is not None and message["text"] != "": | ||
history.append((message["text"], None)) | ||
return history, gr.MultimodalTextbox(value=None, interactive=False) | ||
|
||
|
||
def bot(history): | ||
global vectordb | ||
global tsk | ||
if type(history[-1][0]) != tuple: | ||
if vectordb == "": | ||
pipe = pipeline(tsk, tokenizer=tokenizer, model=model) | ||
response = pipe(history[-1][0])[0] | ||
response = response["generated_text"] | ||
history[-1][1] = "" | ||
for character in response: | ||
history[-1][1] += character | ||
time.sleep(0.05) | ||
yield history | ||
else: | ||
try: | ||
response = just_chatting(model=model, tokenizer=tokenizer, query=history[-1][0], vectordb=vectordb, chat_history=[convert_none_to_str(his) for his in history])["answer"] | ||
history[-1][1] = "" | ||
for character in response: | ||
history[-1][1] += character | ||
time.sleep(0.05) | ||
yield history | ||
except Exception as e: | ||
response = f"Sorry, the error '{e}' occured while generating the response; check [troubleshooting documentation](https://astrabert.github.io/everything-rag/#troubleshooting) for more" | ||
if type(history[-1][0]) == tuple: | ||
filelist = [] | ||
for i in history[-1][0]: | ||
filelist.append(i) | ||
finalpdf = merge_pdfs(filelist) | ||
vectordb = create_a_persistent_db(finalpdf, os.path.dirname(finalpdf)+"_localDB", os.path.dirname(finalpdf)+"_embcache") | ||
response = "VectorDB was successfully created, now you can ask me anything about the document you uploaded!😊" | ||
history[-1][1] = "" | ||
for character in response: | ||
history[-1][1] += character | ||
time.sleep(0.05) | ||
yield history | ||
|
||
with gr.Blocks() as demo: | ||
chatbot = gr.Chatbot( | ||
[[None, "Hi, I'm **everything-rag**🤖.\nI'm here to assist you and let you chat with _your_ pdfs!\nCheck [my website](https://astrabert.github.io/everything-rag/) for troubleshooting and documentation reference\nHave fun!😊"]], | ||
label="everything-rag", | ||
elem_id="chatbot", | ||
bubble_full_width=False, | ||
) | ||
|
||
chat_input = gr.MultimodalTextbox(interactive=True, file_types=["pdf"], placeholder="Enter message or upload file...", show_label=False) | ||
|
||
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input]) | ||
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response") | ||
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input]) | ||
|
||
chatbot.like(print_like_dislike, None, None) | ||
gr.ClearButton(chatbot) | ||
demo.queue() | ||
if __name__ == "__main__": | ||
demo.launch() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
langchain-community==0.0.13 | ||
langchain==0.1.1 | ||
pypdf==3.17.4 | ||
sentence_transformers==2.2.2 | ||
chromadb==0.4.22 | ||
gradio | ||
torch | ||
transformers | ||
trl | ||
peft |
Oops, something went wrong.