Cazimir Roman commited on
Commit
7e0ee7f
1 Parent(s): 41bc40f

initial commit

Browse files
Files changed (2) hide show
  1. app.py +78 -0
  2. requirements.txt +12 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ from langchain import HuggingFaceHub
4
+
5
+ from langchain.chains.question_answering import load_qa_chain
6
+
7
+ from langchain.document_loaders import UnstructuredURLLoader
8
+
9
+ import os
10
+
11
+ with st.sidebar:
12
+ st.title('🌎 Summarize your webpage')
13
+ st.markdown('''
14
+ ## About
15
+ This app is using:
16
+ - [Streamlit](https://streamlit.io/)
17
+ - [LangChain](https://python.langchain.com/)
18
+ - [Flan Alpaca Large](https://huggingface.co/declare-lab/flan-alpaca-large) LLM model
19
+
20
+ ## How it works
21
+ - Load up a web URL
22
+ - Send the request to the LLM using the *load_qa_chain* in langchain
23
+ - Get the answer and from Flan Alpaca Large LLM (open source model on HuggingFace)
24
+
25
+ ''')
26
+ st.write('Made with 🤖 by [Cazimir Roman](https://cazimir.dev)')
27
+
28
+ def load_app():
29
+ llm = HuggingFaceHub(repo_id="declare-lab/flan-alpaca-large", model_kwargs={"temperature":0, "max_length":512})
30
+
31
+ col1, col2 = st.columns([0.8, 0.2])
32
+
33
+ url = col1.text_input('Enter a webpage url here to summarize')
34
+ col2.write("")
35
+ col2.write("")
36
+ summarize = col2.button("Summarize")
37
+
38
+ if url:
39
+ loader = UnstructuredURLLoader(urls=[url])
40
+ data = loader.load()
41
+
42
+ if summarize:
43
+ with st.spinner("Summarizing..."):
44
+ chain = load_qa_chain(llm=llm, chain_type="stuff")
45
+ response = chain.run(input_documents=data, question="Summarize this article in one paragraph")
46
+ st.success(response)
47
+
48
+ def main():
49
+
50
+ st.header("Summarize your webpage")
51
+
52
+ col1, col2 = st.columns([0.8, 0.2])
53
+
54
+ container = col1.container()
55
+
56
+ with container:
57
+ hugging_face_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
58
+ api_key = container.text_input("Enter your HuggingFace API token", type="password", value="" if hugging_face_token == None else hugging_face_token)
59
+ st.markdown('''You can find your token [here](https://huggingface.co/settings/tokens)''')
60
+
61
+ col2.write("")
62
+ col2.write("")
63
+ submit = col2.button("Submit")
64
+
65
+ if hugging_face_token:
66
+ load_app()
67
+
68
+ # submit button is pressed
69
+ if submit:
70
+ # check if api key length correct
71
+ if len(api_key) == 37:
72
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
73
+ load_app()
74
+ else:
75
+ st.error("Api key is not correct")
76
+
77
+ if __name__ == '__main__':
78
+ main()
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain==0.0.137
2
+ PyPDF2
3
+ python-dotenv
4
+ streamlit==1.22.0
5
+ faiss-cpu
6
+ streamlit-extras
7
+ openai
8
+ altair<5
9
+ tiktoken
10
+ huggingface_hub
11
+ sentence_transformers
12
+ unstructured