Commit
·
52847d5
1
Parent(s):
f3ae29f
Upload 3 files
Browse files- Dockerfile +16 -0
- app.py +106 -0
- requirements.txt +113 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
RUN python3 -m pip install --no-cache-dir --upgrade pip
|
7 |
+
RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["panel", "serve", "/code/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
|
12 |
+
|
13 |
+
RUN mkdir /.cache
|
14 |
+
RUN chmod 777 /.cache
|
15 |
+
RUN mkdir .chroma
|
16 |
+
RUN chmod 777 .chroma
|
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import hvplot.pandas
|
2 |
+
import numpy as np
|
3 |
+
import panel as pn
|
4 |
+
import pandas as pd
|
5 |
+
import openai
|
6 |
+
from llama_index import VectorStoreIndex, download_loader
|
7 |
+
from langchain.agents import initialize_agent, Tool
|
8 |
+
from langchain.llms import OpenAI
|
9 |
+
from langchain.chains.conversation.memory import ConversationBufferMemory
|
10 |
+
from panel.chat import ChatInterface
|
11 |
+
import time
|
12 |
+
pn.extension("perspective")
|
13 |
+
|
14 |
+
def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
|
15 |
+
message = f"Echoing {user}: {contents}"
|
16 |
+
return message
|
17 |
+
chat_interface = pn.chat.ChatInterface(callback=callback)
|
18 |
+
msg_panel = chat_interface.send(
|
19 |
+
"Enter a WEB link and ask anything!-\nNote: images in the link will be ignored!!!",
|
20 |
+
user="assistant",
|
21 |
+
respond=False,
|
22 |
+
)
|
23 |
+
website_url_input = pn.widgets.TextInput(name='Website URL', placeholder="https://www.google.com/")
|
24 |
+
submit = pn.widgets.Button(name='Submit', button_type='primary')
|
25 |
+
|
26 |
+
|
27 |
+
def on_submit(event, contents, ):
|
28 |
+
|
29 |
+
try:
|
30 |
+
SimpleWebPageReader = download_loader("SimpleWebPageReader")
|
31 |
+
|
32 |
+
# Set OpenAI API key
|
33 |
+
openai.api_key = "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" # Replace with your actual API key
|
34 |
+
|
35 |
+
# Get the entered website URL
|
36 |
+
website_url = website_url_input.value
|
37 |
+
|
38 |
+
if website_url:
|
39 |
+
# Initialize SimpleWebPageReader with the provided website URL
|
40 |
+
loader = SimpleWebPageReader()
|
41 |
+
documents = loader.load_data(urls=[website_url])
|
42 |
+
|
43 |
+
# Create VectorStoreIndex from documents
|
44 |
+
index = VectorStoreIndex.from_documents(documents)
|
45 |
+
|
46 |
+
# Initialize LangChain OpenAI
|
47 |
+
index = VectorStoreIndex.from_documents(documents)
|
48 |
+
llm = OpenAI(openai_api_key="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", temperature=0, streaming = True
|
49 |
+
)
|
50 |
+
|
51 |
+
# Initialize ConversationBufferMemory
|
52 |
+
memory = ConversationBufferMemory(memory_key="chat_history")
|
53 |
+
|
54 |
+
# Initialize agent chain
|
55 |
+
tools = [
|
56 |
+
Tool(
|
57 |
+
name="Website Index",
|
58 |
+
func=lambda q: index.as_query_engine(),
|
59 |
+
description="Useful when you want to answer questions about the text on websites.",
|
60 |
+
),
|
61 |
+
]
|
62 |
+
|
63 |
+
|
64 |
+
query_engine = index.as_query_engine()
|
65 |
+
response = query_engine.query(contents)
|
66 |
+
|
67 |
+
return str(response),
|
68 |
+
|
69 |
+
except Exception as e:
|
70 |
+
print(f"Error: {e}")
|
71 |
+
def even_or_odd(contents, user, instance):
|
72 |
+
response_tuple = on_submit(event='', contents=contents)
|
73 |
+
|
74 |
+
# Extracting the first element of the tuple and converting it to a string
|
75 |
+
response_string = str(response_tuple)
|
76 |
+
|
77 |
+
return response_string
|
78 |
+
# Set the callback function for the button click event
|
79 |
+
submit.on_click(on_submit)
|
80 |
+
|
81 |
+
# Instantiate the template with widgets displayed in the sidebar
|
82 |
+
template = pn.template.BootstrapTemplate(
|
83 |
+
title='Chat with Web',
|
84 |
+
sidebar=[website_url_input, submit,
|
85 |
+
msg_panel],
|
86 |
+
header=[],
|
87 |
+
|
88 |
+
)
|
89 |
+
|
90 |
+
ChatInterface(callback=even_or_odd)
|
91 |
+
def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
|
92 |
+
message = query_engine.query(contents)
|
93 |
+
return message
|
94 |
+
|
95 |
+
template.main.append(
|
96 |
+
|
97 |
+
ChatInterface(
|
98 |
+
callback=even_or_odd,
|
99 |
+
user="User",
|
100 |
+
avatar="🧑",
|
101 |
+
callback_user="System",
|
102 |
+
)
|
103 |
+
)
|
104 |
+
|
105 |
+
# Display the app
|
106 |
+
template.servable()
|
requirements.txt
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
panel
|
2 |
+
jupyter
|
3 |
+
transformers
|
4 |
+
numpy
|
5 |
+
torch
|
6 |
+
aiohttp
|
7 |
+
aiohttp==3.9.1
|
8 |
+
aiosignal==1.3.1
|
9 |
+
altair==5.2.0
|
10 |
+
annotated-types==0.6.0
|
11 |
+
anyio==4.2.0
|
12 |
+
async-timeout==4.0.3
|
13 |
+
attrs==23.1.0
|
14 |
+
beautifulsoup4==4.12.2
|
15 |
+
bleach==6.1.0
|
16 |
+
blinker==1.7.0
|
17 |
+
bokeh==3.3.2
|
18 |
+
cachetools==5.3.2
|
19 |
+
certifi==2023.11.17
|
20 |
+
charset-normalizer==3.3.2
|
21 |
+
click==8.1.7
|
22 |
+
colorama==0.4.6
|
23 |
+
colorcet==3.0.1
|
24 |
+
contourpy==1.2.0
|
25 |
+
dataclasses-json==0.6.3
|
26 |
+
Deprecated==1.2.14
|
27 |
+
distro==1.8.0
|
28 |
+
exceptiongroup==1.2.0
|
29 |
+
frozenlist==1.4.1
|
30 |
+
fsspec==2023.12.2
|
31 |
+
gitdb==4.0.11
|
32 |
+
GitPython==3.1.40
|
33 |
+
greenlet==3.0.3
|
34 |
+
h11==0.14.0
|
35 |
+
holoviews==1.18.1
|
36 |
+
html2text==2020.1.16
|
37 |
+
httpcore==1.0.2
|
38 |
+
httpx==0.26.0
|
39 |
+
hvplot==0.9.1
|
40 |
+
idna==3.6
|
41 |
+
importlib-metadata==6.11.0
|
42 |
+
Jinja2==3.1.2
|
43 |
+
joblib==1.3.2
|
44 |
+
jsonpatch==1.33
|
45 |
+
jsonpointer==2.4
|
46 |
+
jsonschema==4.20.0
|
47 |
+
jsonschema-specifications==2023.11.2
|
48 |
+
langchain==0.0.352
|
49 |
+
langchain-community==0.0.6
|
50 |
+
langchain-core==0.1.3
|
51 |
+
langsmith==0.0.74
|
52 |
+
linkify-it-py==2.0.2
|
53 |
+
llama-index==0.9.21
|
54 |
+
Markdown==3.5.1
|
55 |
+
markdown-it-py==3.0.0
|
56 |
+
MarkupSafe==2.1.3
|
57 |
+
marshmallow==3.20.1
|
58 |
+
mdit-py-plugins==0.4.0
|
59 |
+
mdurl==0.1.2
|
60 |
+
multidict==6.0.4
|
61 |
+
mypy-extensions==1.0.0
|
62 |
+
nest-asyncio==1.5.8
|
63 |
+
nltk==3.8.1
|
64 |
+
numpy==1.26.2
|
65 |
+
openai==1.6.1
|
66 |
+
packaging==23.2
|
67 |
+
pandas==2.1.4
|
68 |
+
panel==1.3.6
|
69 |
+
param==2.0.1
|
70 |
+
Pillow==10.1.0
|
71 |
+
protobuf==4.25.1
|
72 |
+
pyarrow==14.0.2
|
73 |
+
pyct==0.5.0
|
74 |
+
pydantic==2.5.3
|
75 |
+
pydantic_core==2.14.6
|
76 |
+
pydeck==0.8.1b0
|
77 |
+
Pygments==2.17.2
|
78 |
+
python-dateutil==2.8.2
|
79 |
+
pytz==2023.3.post1
|
80 |
+
pyviz_comms==3.0.0
|
81 |
+
PyYAML==6.0.1
|
82 |
+
rank-bm25==0.2.2
|
83 |
+
referencing==0.32.0
|
84 |
+
regex==2023.10.3
|
85 |
+
requests==2.31.0
|
86 |
+
rich==13.7.0
|
87 |
+
rpds-py==0.15.2
|
88 |
+
six==1.16.0
|
89 |
+
smmap==5.0.1
|
90 |
+
sniffio==1.3.0
|
91 |
+
soupsieve==2.5
|
92 |
+
SQLAlchemy==2.0.23
|
93 |
+
streamlit==1.29.0
|
94 |
+
streamlit-chat==0.1.1
|
95 |
+
tenacity==8.2.3
|
96 |
+
tiktoken==0.5.2
|
97 |
+
toml==0.10.2
|
98 |
+
toolz==0.12.0
|
99 |
+
tornado==6.4
|
100 |
+
tqdm==4.66.1
|
101 |
+
typing-inspect==0.9.0
|
102 |
+
typing_extensions==4.9.0
|
103 |
+
tzdata==2023.3
|
104 |
+
tzlocal==5.2
|
105 |
+
uc-micro-py==1.0.2
|
106 |
+
urllib3==2.1.0
|
107 |
+
validators==0.22.0
|
108 |
+
watchdog==3.0.0
|
109 |
+
webencodings==0.5.1
|
110 |
+
wrapt==1.16.0
|
111 |
+
xyzservices==2023.10.1
|
112 |
+
yarl==1.9.4
|
113 |
+
zipp==3.17.0
|