Enoch1359 commited on
Commit
07c391d
Β·
verified Β·
1 Parent(s): 3026c0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -42,37 +42,38 @@ for i in range(3):
42
 
43
  purs=st.button("gotcha", disabled=not any(url.strip() for url in urs))
44
  if purs:
45
- st.write(urs)
46
- mp.text("Loading..URl..Loader....β˜‘οΈβ˜‘οΈβ˜‘οΈ")
47
- sic=UnstructuredURLLoader(urls=urs)
48
- docs=sic.load()
49
- st.write(len(docs))
50
- mp.text("Loading..txt..splitter....β˜‘οΈβ˜‘οΈβ˜‘οΈ")
51
- tot=RecursiveCharacterTextSplitter.from_tiktoken_encoder(encoding_name="cl100k_base",chunk_size=512,chunk_overlap=16)
52
- doccs=tot.split_documents(docs)
53
- st.write(len(doccs))
54
- mp.text("Loading..VB...β˜‘οΈβ˜‘οΈβ˜‘οΈ")
55
- vv=Chroma.from_documents(doccs,m1)
56
- r2=vv.as_retriever(search_type="similarity",search_kwargs={"k":4})
57
- mp.text("Loading..Retri....β˜‘οΈβ˜‘οΈβ˜‘οΈ")
58
- ra1=RetrievalQAWithSourcesChain.from_chain_type(llm=llm,retriever=r2,chain_type="map_reduce")
59
- st.session_state.ra1=ra1
60
- mp.text("DB & Retri Done βœ…βœ…βœ…")
61
- time.sleep(3)
 
62
  query=mp.text_input("UR Question??")
63
  if query:
64
- if "ra1" not in st.session_state:
65
- st.warning("pls give ur urls")
66
- else:
67
- with st.spinner("Wait for it..."):
68
- result=st.session_state.ra1({"question":query},return_only_outputs=True)
69
- st.header("Answer")
70
- st.subheader(result["answer"])
71
- g = st.button("Source")
72
- if g:
73
- sources = result.get("sources", "")
74
- st.subheader("Sources")
75
- for line in sources.split("\n"):
76
- st.write(line)
77
 
78
 
 
42
 
43
  purs=st.button("gotcha", disabled=not any(url.strip() for url in urs))
44
  if purs:
45
+ urs = [url.strip() for url in urs if url.strip()]
46
+ st.write(urs)
47
+ mp.text("Loading..URl..Loader....β˜‘οΈβ˜‘οΈβ˜‘οΈ")
48
+ sic=UnstructuredURLLoader(urls=urs)
49
+ docs=sic.load()
50
+ st.write(len(docs))
51
+ mp.text("Loading..txt..splitter....β˜‘οΈβ˜‘οΈβ˜‘οΈ")
52
+ tot=RecursiveCharacterTextSplitter.from_tiktoken_encoder(encoding_name="cl100k_base",chunk_size=512,chunk_overlap=16)
53
+ doccs=tot.split_documents(docs)
54
+ st.write(len(doccs))
55
+ mp.text("Loading..VB...β˜‘οΈβ˜‘οΈβ˜‘οΈ")
56
+ vv=Chroma.from_documents(doccs,m1)
57
+ r2=vv.as_retriever(search_type="similarity",search_kwargs={"k":4})
58
+ mp.text("Loading..Retri....β˜‘οΈβ˜‘οΈβ˜‘οΈ")
59
+ ra1=RetrievalQAWithSourcesChain.from_chain_type(llm=llm,retriever=r2,chain_type="map_reduce")
60
+ st.session_state.ra1=ra1
61
+ mp.text("DB & Retri Done βœ…βœ…βœ…")
62
+ time.sleep(3)
63
  query=mp.text_input("UR Question??")
64
  if query:
65
+ if "ra1" not in st.session_state:
66
+ st.warning("pls give ur urls")
67
+ else:
68
+ with st.spinner("Wait for it..."):
69
+ result=st.session_state.ra1({"question":query},return_only_outputs=True)
70
+ st.header("Answer")
71
+ st.subheader(result["answer"])
72
+ g = st.button("Source")
73
+ if g:
74
+ sources = result.get("sources", "")
75
+ st.subheader("Sources")
76
+ for line in sources.split("\n"):
77
+ st.write(line)
78
 
79