Spaces:
Sleeping
Sleeping
Jagadish Krishnamoorthy
commited on
Add doc loader
Browse files- app.py +27 -5
- requirements.txt +76 -0
app.py
CHANGED
@@ -1,6 +1,25 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Initialize chat history
|
6 |
if "messages" not in st.session_state:
|
@@ -12,16 +31,19 @@ for message in st.session_state.messages:
|
|
12 |
st.markdown(message["content"])
|
13 |
|
14 |
# React to user input
|
15 |
-
if prompt := st.chat_input("
|
16 |
# Display user message in chat message container
|
17 |
st.chat_message("user").markdown(prompt)
|
18 |
# Add user message to chat history
|
19 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
20 |
|
21 |
-
response =
|
|
|
|
|
|
|
22 |
# Display assistant response in chat message container
|
23 |
with st.chat_message("assistant"):
|
24 |
-
st.markdown(response)
|
25 |
# Add assistant response to chat history
|
26 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
27 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from langchain_openai import ChatOpenAI
|
3 |
+
from langchain_core.prompts import ChatPromptTemplate
|
4 |
+
from langchain_community.document_loaders import WebBaseLoader
|
5 |
|
6 |
+
default_url = "https://rocm.docs.amd.com/en/latest/what-is-rocm.html"
|
7 |
+
st.title("URL Loader")
|
8 |
+
|
9 |
+
url = st.text_input("Provide URL ", default_url)
|
10 |
+
if "url_dict" not in st.session_state:
|
11 |
+
st.session_state.url_dict = {}
|
12 |
+
if url not in st.session_state.url_dict:
|
13 |
+
loader = WebBaseLoader(url)
|
14 |
+
st.session_state.url_dict[url] = loader.load()
|
15 |
+
|
16 |
+
llm = ChatOpenAI(temperature=0.1)
|
17 |
+
prompt = ChatPromptTemplate.from_template("""
|
18 |
+
Answer the user's question:
|
19 |
+
Context: {context}
|
20 |
+
Question : {input}
|
21 |
+
""")
|
22 |
+
chain = prompt | llm
|
23 |
|
24 |
# Initialize chat history
|
25 |
if "messages" not in st.session_state:
|
|
|
31 |
st.markdown(message["content"])
|
32 |
|
33 |
# React to user input
|
34 |
+
if prompt := st.chat_input("Ask Question to the URL provided"):
|
35 |
# Display user message in chat message container
|
36 |
st.chat_message("user").markdown(prompt)
|
37 |
# Add user message to chat history
|
38 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
39 |
|
40 |
+
response = chain.invoke({
|
41 |
+
"context" : [st.session_state.url_dict[url]],
|
42 |
+
"input" : prompt
|
43 |
+
})
|
44 |
# Display assistant response in chat message container
|
45 |
with st.chat_message("assistant"):
|
46 |
+
st.markdown(response.content)
|
47 |
# Add assistant response to chat history
|
48 |
+
st.session_state.messages.append({"role": "assistant", "content": response.content})
|
49 |
|
requirements.txt
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiohttp==3.9.5
|
2 |
+
aiosignal==1.3.1
|
3 |
+
altair==5.3.0
|
4 |
+
annotated-types==0.6.0
|
5 |
+
anyio==4.3.0
|
6 |
+
attrs==23.2.0
|
7 |
+
beautifulsoup4==4.12.3
|
8 |
+
blinker==1.8.2
|
9 |
+
bs4==0.0.2
|
10 |
+
cachetools==5.3.3
|
11 |
+
certifi==2024.2.2
|
12 |
+
charset-normalizer==3.3.2
|
13 |
+
click==8.1.7
|
14 |
+
dataclasses-json==0.6.6
|
15 |
+
distro==1.9.0
|
16 |
+
frozenlist==1.4.1
|
17 |
+
gitdb==4.0.11
|
18 |
+
GitPython==3.1.43
|
19 |
+
h11==0.14.0
|
20 |
+
httpcore==1.0.5
|
21 |
+
httpx==0.27.0
|
22 |
+
idna==3.7
|
23 |
+
Jinja2==3.1.4
|
24 |
+
jsonpatch==1.33
|
25 |
+
jsonpointer==2.4
|
26 |
+
jsonschema==4.22.0
|
27 |
+
jsonschema-specifications==2023.12.1
|
28 |
+
langchain==0.2.0
|
29 |
+
langchain-community==0.2.0
|
30 |
+
langchain-core==0.2.0
|
31 |
+
langchain-openai==0.1.7
|
32 |
+
langchain-text-splitters==0.2.0
|
33 |
+
langsmith==0.1.59
|
34 |
+
markdown-it-py==3.0.0
|
35 |
+
MarkupSafe==2.1.5
|
36 |
+
marshmallow==3.21.2
|
37 |
+
mdurl==0.1.2
|
38 |
+
multidict==6.0.5
|
39 |
+
mypy-extensions==1.0.0
|
40 |
+
numpy==1.26.4
|
41 |
+
openai==1.30.1
|
42 |
+
orjson==3.10.3
|
43 |
+
packaging==23.2
|
44 |
+
pandas==2.2.2
|
45 |
+
pillow==10.3.0
|
46 |
+
protobuf==4.25.3
|
47 |
+
pyarrow==16.1.0
|
48 |
+
pydantic==2.7.1
|
49 |
+
pydantic_core==2.18.2
|
50 |
+
pydeck==0.9.1
|
51 |
+
Pygments==2.18.0
|
52 |
+
python-dateutil==2.9.0.post0
|
53 |
+
pytz==2024.1
|
54 |
+
PyYAML==6.0.1
|
55 |
+
referencing==0.35.1
|
56 |
+
regex==2024.5.15
|
57 |
+
requests==2.31.0
|
58 |
+
rich==13.7.1
|
59 |
+
rpds-py==0.18.1
|
60 |
+
six==1.16.0
|
61 |
+
smmap==5.0.1
|
62 |
+
sniffio==1.3.1
|
63 |
+
soupsieve==2.5
|
64 |
+
SQLAlchemy==2.0.30
|
65 |
+
streamlit==1.34.0
|
66 |
+
tenacity==8.3.0
|
67 |
+
tiktoken==0.7.0
|
68 |
+
toml==0.10.2
|
69 |
+
toolz==0.12.1
|
70 |
+
tornado==6.4
|
71 |
+
tqdm==4.66.4
|
72 |
+
typing-inspect==0.9.0
|
73 |
+
typing_extensions==4.11.0
|
74 |
+
tzdata==2024.1
|
75 |
+
urllib3==2.2.1
|
76 |
+
yarl==1.9.4
|