CazimirRoman commited on
Commit
a65fb24
·
1 Parent(s): 2a12658

initial commit

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