Spaces:
Sleeping
Sleeping
Commit
·
09775a5
1
Parent(s):
35ae8a7
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,7 +82,6 @@ def remove_context(text):
|
|
| 82 |
print(f"处理多余的Context文本函数定义结束")
|
| 83 |
|
| 84 |
url="https://www.usinoip.com"
|
| 85 |
-
#url="https://www.usinoip.com/UpdatesAbroad/290.html"
|
| 86 |
texts=""
|
| 87 |
raw_text=""
|
| 88 |
user_question = ""
|
|
@@ -121,10 +120,17 @@ st.markdown(
|
|
| 121 |
|
| 122 |
user_question = st.text_input("Enter your query here and AI-Chat with your website:")
|
| 123 |
|
| 124 |
-
text_splitter = CharacterTextSplitter(
|
| 125 |
-
separator = "\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
chunk_size = 1000,
|
| 127 |
-
chunk_overlap = 200,
|
| 128 |
length_function = len,
|
| 129 |
)
|
| 130 |
|
|
@@ -137,12 +143,8 @@ with st.sidebar:
|
|
| 137 |
st.subheader("Enjoy Chatting!")
|
| 138 |
st.sidebar.markdown('<span class="blue-underline">Life Enhancing with AI.</span>', unsafe_allow_html=True)
|
| 139 |
try:
|
| 140 |
-
with st.spinner("Preparing website materials for you..."):
|
| 141 |
-
|
| 142 |
-
#url="https://www.usinoip.com"
|
| 143 |
-
#url_loader = WebBaseLoader([url])
|
| 144 |
-
#urls = [ 'https://www.usinoip.com/AI3KEYS.html', 'https://www.usinoip.com/AIInsights/308.html']
|
| 145 |
-
url_loader=WebBaseLoader(["https://www.usinoip.com/AI3KEYS.html"])
|
| 146 |
raw_text = url_loader.load()
|
| 147 |
page_content = raw_text[0].page_content
|
| 148 |
page_content = str(page_content)
|
|
@@ -151,10 +153,9 @@ with st.sidebar:
|
|
| 151 |
initial_embeddings=get_embeddings(texts)
|
| 152 |
db_embeddings = torch.FloatTensor(initial_embeddings)
|
| 153 |
except Exception as e:
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
pass
|
| 158 |
|
| 159 |
if st.button('Get AI Response'):
|
| 160 |
if user_question !="" and not user_question.strip().isspace() and not user_question == "" and not user_question.strip() == "" and not user_question.isspace():
|
|
|
|
| 82 |
print(f"处理多余的Context文本函数定义结束")
|
| 83 |
|
| 84 |
url="https://www.usinoip.com"
|
|
|
|
| 85 |
texts=""
|
| 86 |
raw_text=""
|
| 87 |
user_question = ""
|
|
|
|
| 120 |
|
| 121 |
user_question = st.text_input("Enter your query here and AI-Chat with your website:")
|
| 122 |
|
| 123 |
+
#text_splitter = CharacterTextSplitter(
|
| 124 |
+
# separator = "\n",
|
| 125 |
+
# chunk_size = 1000,
|
| 126 |
+
# chunk_overlap = 200,
|
| 127 |
+
# length_function = len,
|
| 128 |
+
#)
|
| 129 |
+
|
| 130 |
+
text_splitter = RecursiveCharacterTextSplitter(
|
| 131 |
+
#separator = "\n",
|
| 132 |
chunk_size = 1000,
|
| 133 |
+
chunk_overlap = 200, #striding over the text
|
| 134 |
length_function = len,
|
| 135 |
)
|
| 136 |
|
|
|
|
| 143 |
st.subheader("Enjoy Chatting!")
|
| 144 |
st.sidebar.markdown('<span class="blue-underline">Life Enhancing with AI.</span>', unsafe_allow_html=True)
|
| 145 |
try:
|
| 146 |
+
with st.spinner("Preparing website materials for you..."):
|
| 147 |
+
url_loader = WebBaseLoader([url])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
raw_text = url_loader.load()
|
| 149 |
page_content = raw_text[0].page_content
|
| 150 |
page_content = str(page_content)
|
|
|
|
| 153 |
initial_embeddings=get_embeddings(texts)
|
| 154 |
db_embeddings = torch.FloatTensor(initial_embeddings)
|
| 155 |
except Exception as e:
|
| 156 |
+
st.write("Unknow error.")
|
| 157 |
+
print("Please enter a valide URL.")
|
| 158 |
+
st.stop()
|
|
|
|
| 159 |
|
| 160 |
if st.button('Get AI Response'):
|
| 161 |
if user_question !="" and not user_question.strip().isspace() and not user_question == "" and not user_question.strip() == "" and not user_question.isspace():
|