Update app.py
Browse files
app.py
CHANGED
|
@@ -46,28 +46,30 @@ if url !="" and not url.strip().isspace() and not url == "" and not url.strip()
|
|
| 46 |
try:
|
| 47 |
#loader = WebBaseLoader("https://www.usinoip.com/")
|
| 48 |
with st.spinner("AI Thinking...Please wait a while to Cheers!"):
|
| 49 |
-
print("
|
| 50 |
loader = WebBaseLoader(url)
|
| 51 |
-
print("2")
|
| 52 |
docs = loader.load()
|
| 53 |
-
print(docs)
|
| 54 |
split_docs = text_splitter_rcs.split_documents(docs)
|
| 55 |
-
print("3")
|
| 56 |
print(split_docs)
|
|
|
|
| 57 |
#result=chain.run(docs) #这个result的格式比较特殊,可以直接print,但不可以和其他字符串联合print输出 - this step errors!
|
| 58 |
-
result=chain.run(split_docs)
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
#print("AI Summarization: "+result) #这个会出错,原因见上方
|
| 64 |
print("AI Summarization:")
|
| 65 |
#print(result)
|
| 66 |
-
print(
|
| 67 |
|
| 68 |
st.write("AI Summarization:")
|
| 69 |
#st.write(result)
|
| 70 |
-
st.write(
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
st.write("Wrong URL or URL not parsable.")
|
|
|
|
| 46 |
try:
|
| 47 |
#loader = WebBaseLoader("https://www.usinoip.com/")
|
| 48 |
with st.spinner("AI Thinking...Please wait a while to Cheers!"):
|
| 49 |
+
print("Website to Chat: "+url)
|
| 50 |
loader = WebBaseLoader(url)
|
|
|
|
| 51 |
docs = loader.load()
|
|
|
|
| 52 |
split_docs = text_splitter_rcs.split_documents(docs)
|
|
|
|
| 53 |
print(split_docs)
|
| 54 |
+
print()
|
| 55 |
#result=chain.run(docs) #这个result的格式比较特殊,可以直接print,但不可以和其他字符串联合print输出 - this step errors!
|
| 56 |
+
result=chain.run(split_docs) #找到之前总是POST Error的原因:chain.run(docs)的结果,格式不是str,导致程序错误
|
| 57 |
+
result=str(result)
|
| 58 |
+
cleaned_initial_ai_response = remove_context(result)
|
| 59 |
+
print(cleaned_initial_ai_response)
|
| 60 |
+
print()
|
| 61 |
+
final_ai_response = cleaned_initial_ai_response.split('<|end|>')[0].strip().replace('\n\n', '\n').replace('<|end|>', '').replace('<|user|>', '').replace('<|system|>', '').replace('<|assistant|>', '')
|
| 62 |
+
new_final_ai_response = final_ai_response.split('Unhelpful Answer:')[0].strip()
|
| 63 |
+
final_result = new_final_ai_response.split('Note:')[0].strip()
|
| 64 |
|
| 65 |
#print("AI Summarization: "+result) #这个会出错,原因见上方
|
| 66 |
print("AI Summarization:")
|
| 67 |
#print(result)
|
| 68 |
+
print(final_result)
|
| 69 |
|
| 70 |
st.write("AI Summarization:")
|
| 71 |
#st.write(result)
|
| 72 |
+
st.write(final_result)
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
st.write("Wrong URL or URL not parsable.")
|