Shivam commited on
Commit
d3319a1
·
unverified ·
1 Parent(s): 23efbe1

Add files via upload

Browse files
Files changed (3) hide show
  1. web.jpeg +0 -0
  2. youtube-summary.py +95 -0
  3. youtubeLogo.jpg +0 -0
web.jpeg ADDED
youtube-summary.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import validators
3
+ import os
4
+ from dotenv import load_dotenv
5
+ from langchain_groq import ChatGroq
6
+ from langchain_core.prompts import PromptTemplate
7
+ from langchain.chains.summarize import load_summarize_chain
8
+ from langchain_community.document_loaders import YoutubeLoader,UnstructuredURLLoader
9
+ from PIL import Image
10
+
11
+ load_dotenv()
12
+
13
+ groq_api_key = os.getenv('GROQ_API_KEY')
14
+
15
+ img1 = Image.open(r'D:\UDEMY\GenAI\Langchain\Text Summarization\youtubeLogo.jpg')
16
+
17
+ img2 = Image.open(r'D:\UDEMY\GenAI\Langchain\Text Summarization\web.jpeg')
18
+
19
+ st.set_page_config(page_title='Summarizer')
20
+
21
+ col1,col2,col3 = st.columns([1,1,3])
22
+
23
+ with col1:
24
+ st.image(img1,use_column_width=True)
25
+
26
+ with col2:
27
+ st.image(img2,use_column_width=True)
28
+
29
+ with col3:
30
+ st.title('Summarize Youtube Videos / Web Page')
31
+
32
+
33
+ llm = ChatGroq(model='Gemma2-9b-It',groq_api_key=groq_api_key)
34
+
35
+
36
+ system_prompt = '''
37
+ Summarize the content from given {text} in best possible way.
38
+ '''
39
+
40
+ prompt = PromptTemplate(
41
+ input_variables=['text'],
42
+ template=system_prompt
43
+ )
44
+
45
+ system_prompt_n = '''
46
+ You are an advanced AI summarization tool.Your task is to extract the key points, themes, and essential information from various online content,
47
+ and give the final summary from {text}.
48
+ Analyze the content, focusing on the following criteria:
49
+ 1.Main Ideas: Identify the primary arguments or messages conveyed in the content.
50
+ 2.Supporting Details: Highlight important examples, statistics, or pieces of evidence that reinforce the main ideas.
51
+ 3.Structure: Maintain the original flow of the content, summarizing it in a coherent manner that mirrors the order of presented information.
52
+ 4.Length: Produce a summary that is concise.
53
+ 5.Clarity and Readability: Ensure the summary is written in clear, simple language that is easy to understand, avoiding difficult words unless necessary.
54
+ 6.Contextual Relevance: Tailor the summary based on the intended audience, making sure it is appropriate for their level of understanding and interest.
55
+ '''
56
+
57
+ final_prompt = PromptTemplate(
58
+ input_variables=['text'],
59
+ template=system_prompt_n
60
+ )
61
+
62
+ URL = st.text_input(label='Paste URL here',placeholder='https://www.youtube.com/')
63
+
64
+ if st.button('Summarize the Video/Web-page'):
65
+ if not URL:
66
+ st.info('Please provide the url')
67
+
68
+ elif not validators.url(URL):
69
+ st.warning('Please provide the correct url')
70
+
71
+ else:
72
+ try:
73
+ with st.spinner('Summarizing...'):
74
+ if 'youtube.com' in URL:
75
+ loader = YoutubeLoader.from_youtube_url(URL,add_video_info=True,language=['en-IN','hi','en'])
76
+ else:
77
+ loader = UnstructuredURLLoader([URL],ssl_verify=False,mode='single',
78
+ headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 BingBot/2.0'})
79
+
80
+ docs = loader.load()
81
+
82
+ chain = load_summarize_chain(llm,chain_type='map_reduce',
83
+ map_prompt=prompt,
84
+ combine_prompt=final_prompt)
85
+
86
+ response = chain.run(docs)
87
+
88
+ st.success(response)
89
+
90
+ except Exception as e:
91
+ st.exception(f'Exception : {e}')
92
+
93
+
94
+ # HF_Token
95
+ # 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
youtubeLogo.jpg ADDED