Spaces:
Running
Running
adding app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import validators,streamlit as st
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
from langchain_groq import ChatGroq
|
4 |
+
from langchain.chains.summarize import load_summarize_chain
|
5 |
+
from langchain_community.document_loaders import YoutubeLoader,UnstructuredURLLoader
|
6 |
+
|
7 |
+
|
8 |
+
# setting streamlit
|
9 |
+
st.set_page_config(page_title="DEmo for summarization")
|
10 |
+
st.title("Summarize it for me")
|
11 |
+
|
12 |
+
# groq API
|
13 |
+
#with st.sidebar:
|
14 |
+
# groq_api_key = st.text_input("Groq API Key",value="",type="password")
|
15 |
+
groq_api_key = "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"
|
16 |
+
my_url = st.text_input("URL")
|
17 |
+
|
18 |
+
llm = ChatGroq(model="Gemma-7b-It", groq_api_key=groq_api_key )
|
19 |
+
|
20 |
+
prompt_template="""
|
21 |
+
summarize the following content in not more than 400 words:
|
22 |
+
Content:{text}
|
23 |
+
|
24 |
+
"""
|
25 |
+
|
26 |
+
prompt=PromptTemplate(template=prompt_template,input_variables=["text"])
|
27 |
+
|
28 |
+
if st.button("Summarize the Content from YT or Website"):
|
29 |
+
## Validate all the inputs
|
30 |
+
if not groq_api_key.strip() or not my_url.strip():
|
31 |
+
st.error("Please provide the information to get started")
|
32 |
+
elif not validators.url(my_url):
|
33 |
+
st.error("Please enter a valid Url. It can may be a YT video utl or website url")
|
34 |
+
|
35 |
+
else:
|
36 |
+
try:
|
37 |
+
with st.spinner("Waiting..."):
|
38 |
+
## loading the website or yt video data
|
39 |
+
if "youtube.com" in my_url:
|
40 |
+
loader=YoutubeLoader.from_youtube_url(my_url,add_video_info=True)
|
41 |
+
else:
|
42 |
+
loader=UnstructuredURLLoader(urls=[my_url],ssl_verify=False,
|
43 |
+
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_5_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"})
|
44 |
+
docs=loader.load()
|
45 |
+
|
46 |
+
## Chain For Summarization
|
47 |
+
chain=load_summarize_chain(llm,chain_type="stuff",prompt=prompt)
|
48 |
+
output_summary=chain.run(docs)
|
49 |
+
|
50 |
+
st.success(output_summary)
|
51 |
+
except Exception as e:
|
52 |
+
st.exception(f"Exception:{e}")
|
53 |
+
|
54 |
+
|
55 |
+
|