sancharikadebnath commited on
Commit
45bfcc4
Β·
1 Parent(s): 8d9d2f1

Added summary and ATS

Browse files
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY=AIzaSyAA59xkxMEUqffuaNMzrTxK6m5AJpY3tCw
__pycache__/ats1.cpython-39.pyc ADDED
Binary file (4.9 kB). View file
 
__pycache__/blog.cpython-39.pyc ADDED
Binary file (4.92 kB). View file
 
__pycache__/blogger.cpython-39.pyc ADDED
Binary file (5.04 kB). View file
 
__pycache__/gist.cpython-39.pyc ADDED
Binary file (4.98 kB). View file
 
app.py CHANGED
@@ -1,114 +1,50 @@
1
- import os
2
- import pyperclip
3
  import streamlit as st
4
- from dotenv import load_dotenv
5
- import speech_recognition as sr
6
- import google.generativeai as genai
7
- from langchain.prompts import PromptTemplate
8
- from langchain_google_genai import ChatGoogleGenerativeAI
9
 
10
- load_dotenv()
11
 
12
- def model():
13
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
- return ChatGoogleGenerativeAI(model="gemini-pro")
15
 
16
- def getLLamaresponse(input_text,no_words,blog_style):
17
- ## Prompt Template
18
- template="""
19
- Write a {tone} blog in {lang} as {blog_style} for a topic {input_text} within {no_words} words with references and video links also if possible and ends with a conclusion. {info}
20
- """
21
- prompt=PromptTemplate(input_variables=['tone','lang',"blog_style","input_text",'no_words', "info"],
22
- template=template)
23
- formated_prompt = prompt.format(tone=tone,lang=lang,blog_style=blog_style,input_text=input_text,no_words=no_words,info=info)
24
- ## Generate the ressponse from the LLama 2 model
25
- response=llm.invoke(formated_prompt)
26
- return response.content
27
 
28
- def copy_text(answer, copy_button=False):
29
- pyperclip.copy(answer)
30
- if copy_button:
31
- st.toast("Text copied to clipboard!", icon="πŸ“‹")
32
 
33
- def record_audio():
34
- r = sr.Recognizer()
35
- with st.spinner("Recording..."):
36
- with sr.Microphone() as source:
37
- r.adjust_for_ambient_noise(source) # Adjust for ambient noise
38
- with st.spinner("Say Something..."):
39
- audio = r.listen(source, timeout=5) # Set a timeout for listening
40
- with st.spinner("Processing..."):
41
- # Attempt speech recognition
42
- try:
43
- text = r.recognize_google(audio)
44
- st.session_state['input_text'] = text
45
- return text
46
- except sr.UnknownValueError:
47
- st.write("Sorry, I could not understand what you said. Please try again or write in text box.")
48
- return ""
49
- except sr.RequestError as e:
50
- st.write(f"Could not request results; {e}")
51
- return ""
52
 
53
- def input_state(input_text):
54
- if isinstance(input_text, str):
55
- st.session_state['input_text'] = input_text # Update st.session_state with new text input
56
-
57
-
58
-
59
- st.set_page_config(page_title="AI-Blogger",
60
- page_icon='πŸ€–',
61
- layout='centered' )
62
-
63
- st.header("AI Blogger πŸ€–", divider='rainbow')
64
- hide_streamlit_style = """
65
- <style>
66
- #MainMenu {visibility: hidden;}
67
- footer {visibility: hidden;}
68
- </style>
69
-
70
- """
71
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
72
- #? Make it False in DEV Mode
73
- button_disabled = True
74
- # Button with info hover
75
- if button_disabled:
76
- st.toast("Mic Button is disabled in production. HF Don't have Audio Device")
77
-
78
- col1,col2=st.columns([20,3])
79
- with col1:
80
- st.write('')
81
- text = st.empty()
82
- input_text = text.text_input("Enter the Blog Topic")
83
 
84
- with col2:
85
- st.write(':grey[.]')
86
- recorder = st.button("πŸŽ™οΈ", help="Blog Topic by Voice", key="mic", disabled=button_disabled)
 
 
 
87
 
88
- if recorder:
89
- recorded_text = record_audio()
90
- if recorded_text:
91
- input_text = text.text_input("Enter the Blog Topic",value=recorded_text)
92
 
93
- with st.sidebar:
94
- st.title(' :blue[_AI Generated Blog_] πŸ€–')
95
- # Refactored from <https://github.com/a16z-infra/llama2-chatbot>
96
- st.subheader('Parameters')
97
- no_words = st.sidebar.slider('Maximum Characters', min_value=10, max_value=5000, value=1000, step=100)
98
- blog_style=st.selectbox('Writing the blog for', ('Researchers','Data Scientist','Common People'),index=0)
99
- tone=st.selectbox('Desired Tone', ('Informative','Casual','Persuasive', 'Formal', 'Humorous'),index=0)
100
- lang = st.text_input('Language', 'English')
101
- info = st.text_input('Specific Instruction')
102
- with st.spinner("Loading Model..."):
103
- llm= model()
104
 
105
- submit=st.button("Generate Blog", on_click =lambda: input_state(input_text))
106
- if submit:
107
- with st.spinner("Generating Blog..."):
108
- answer = getLLamaresponse(st.session_state['input_text'],no_words,blog_style)
109
- st.success('Blog Generated!', icon="βœ…")
110
- st.write(answer)
111
- st.markdown(''':orange[Run in your system to access Copy to Clipboard Feature]''')
112
 
113
- ## Uncomment if using in system HF doesn't Support Copy to clipboard
114
- # st.button("πŸ“‹", on_click=copy_text(answer))
 
 
1
+ # app.py
 
2
  import streamlit as st
3
+ import blogger
4
+ import gist
5
+ import pdfplumber
6
+ import ats1
7
+ import docx
8
 
9
+ st.set_page_config(page_title='AI MultiTask', page_icon='πŸ€–', layout='centered')
10
 
11
+ st.title("What You Want To Do")
 
 
12
 
13
+ uploaded_file = st.file_uploader("Choose a document file", type=["pdf", "txt", "csv", "docx"])
14
+ text = ''
15
+ if uploaded_file is not None:
16
+ st.write("File uploaded successfully!")
 
 
 
 
 
 
 
17
 
18
+ file_extension = uploaded_file.name.split(".")[-1]
 
 
 
19
 
20
+ if file_extension == "pdf":
21
+ with pdfplumber.open(uploaded_file) as pdf:
22
+ pages = pdf.pages
23
+ for page in pages:
24
+ text = page.extract_text()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ elif file_extension == "txt":
27
+ text = uploaded_file.getvalue().decode("utf-8")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ elif file_extension == "docx":
30
+ docx_text = docx.Document(uploaded_file)
31
+ full_text = []
32
+ for para in docx_text.paragraphs:
33
+ full_text.append(para.text)
34
+ text = "\n".join(full_text)
35
 
36
+ st.text_area("Extracted From Document",value=text)
37
+ st.session_state['doc_text'] = text
 
 
38
 
39
+ col1, col2, col3 = st.columns([3, 3,3])
40
+ option = st.radio("I want to use: ", ("Blog", "Summerize", "ATS"), horizontal=True)
 
 
 
 
 
 
 
 
 
41
 
42
+ if option == "Blog":
43
+ blogger.run_blogger(st.session_state['doc_text'])
44
+
45
+ elif option == "Summerize":
46
+ gist.run_gist(st.session_state['doc_text'])
 
 
47
 
48
+ elif option == "ATS":
49
+ ats1.run_ats(st.session_state['doc_text'])
50
+
ats.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv()
4
+ import base64
5
+ import streamlit as st
6
+ import os
7
+ import io
8
+ from PIL import Image
9
+ import pdf2image
10
+ import google.generativeai as genai
11
+
12
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
+
14
+ def get_gemini_response(input,pdf_cotent,prompt):
15
+ model=genai.GenerativeModel('gemini-pro-vision')
16
+ response=model.generate_content([input,pdf_content[0],prompt])
17
+ return response.text
18
+
19
+ def input_pdf_setup(uploaded_file):
20
+ if uploaded_file is not None:
21
+ ## Convert the PDF to image
22
+ images=pdf2image.convert_from_bytes(uploaded_file.read(), poppler_path=r'C:\Program Files (x86)\poppler\Library\bin')
23
+
24
+ first_page=images[0]
25
+
26
+ # Convert to bytes
27
+ img_byte_arr = io.BytesIO()
28
+ first_page.save(img_byte_arr, format='JPEG')
29
+ img_byte_arr = img_byte_arr.getvalue()
30
+
31
+ pdf_parts = [
32
+ {
33
+ "mime_type": "image/jpeg",
34
+ "data": base64.b64encode(img_byte_arr).decode() # encode to base64
35
+ }
36
+ ]
37
+ return pdf_parts
38
+ else:
39
+ raise FileNotFoundError("No file uploaded")
40
+
41
+ ## Streamlit App
42
+
43
+ st.set_page_config(page_title="ATS Resume EXpert")
44
+ st.header("ATS Tracking System")
45
+ input_text=st.text_area("Job Description: ",key="input")
46
+ uploaded_file=st.file_uploader("Upload your resume(PDF)...",type=["pdf"])
47
+
48
+
49
+ if uploaded_file is not None:
50
+ st.write("PDF Uploaded Successfully")
51
+
52
+
53
+
54
+ submit1 = st.button("Tell Me About the Resume")
55
+
56
+ #submit2 = st.button("How Can I Improvise my Skills")
57
+
58
+ submit3 = st.button("Percentage match")
59
+
60
+ input_prompt1 = """
61
+ You are an experienced Technical Human Resource Manager,your task is to review the provided resume against the job description.
62
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
63
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
64
+ """
65
+
66
+ input_prompt3 = """
67
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality,
68
+ your task is to evaluate the resume against the provided job description. give me the percentage of match if the resume matches
69
+ the job description. First the output should come as percentage and then keywords missing and last final thoughts.
70
+ """
71
+
72
+ if submit1:
73
+ if uploaded_file is not None:
74
+ pdf_content=input_pdf_setup(uploaded_file)
75
+ response=get_gemini_response(input_prompt1,pdf_content,input_text)
76
+ st.subheader("The Repsonse is")
77
+ st.write(response)
78
+ else:
79
+ st.write("Please uplaod the resume")
80
+
81
+ elif submit3:
82
+ if uploaded_file is not None:
83
+ pdf_content=input_pdf_setup(uploaded_file)
84
+ response=get_gemini_response(input_prompt3,pdf_content,input_text)
85
+ st.subheader("The Repsonse is")
86
+ st.write(response)
87
+ else:
88
+ st.write("Please uplaod the resume")
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
ats1.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pyperclip
3
+ import streamlit as st
4
+ from dotenv import load_dotenv
5
+ import speech_recognition as sr
6
+ import google.generativeai as genai
7
+ from langchain.prompts import PromptTemplate
8
+ from langchain_google_genai import ChatGoogleGenerativeAI
9
+
10
+
11
+ class ATS(object):
12
+ def __init__(self, title="ATS Tracking System"):
13
+ self.title = title
14
+
15
+ @staticmethod
16
+ def model():
17
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
18
+ return ChatGoogleGenerativeAI(model="gemini-pro")
19
+
20
+ @staticmethod
21
+ def get_gemini_response(llm, input_text, doc, template, info=''):
22
+ formated_prompt = template.format(doc=doc, input_text=input_text)
23
+ response = llm.invoke(formated_prompt)
24
+ return response.content
25
+ # return formated_prompt
26
+
27
+ @staticmethod
28
+ def copy_text(answer, copy_button=False):
29
+ pyperclip.copy(answer)
30
+ if copy_button:
31
+ st.toast("Text copied to clipboard!", icon="πŸ“‹")
32
+
33
+ @staticmethod
34
+ def record_audio():
35
+ r = sr.Recognizer()
36
+ with st.spinner("Recording..."):
37
+ with sr.Microphone() as source:
38
+ r.adjust_for_ambient_noise(source)
39
+ with st.spinner("Say Something..."):
40
+ audio = r.listen(source, timeout=5)
41
+ with st.spinner("Processing..."):
42
+ try:
43
+ text = r.recognize_google(audio)
44
+ st.session_state['input_text'] = text
45
+ return text
46
+ except sr.UnknownValueError:
47
+ st.write("Sorry, I could not understand what you said. Please try again or write in text box.")
48
+ return ""
49
+ except sr.RequestError as e:
50
+ st.write(f"Could not request results; {e}")
51
+ return ""
52
+
53
+ @staticmethod
54
+ def input_state(input_text):
55
+ if isinstance(input_text, str):
56
+ st.session_state['input_text'] = input_text
57
+
58
+
59
+ def run_ats(doc=''):
60
+ load_dotenv()
61
+ ats = ATS()
62
+ st.header(ats.title + " πŸ€–", divider='rainbow')
63
+ input_text=st.text_area("Job Description: ",key="input")
64
+ # uploaded_file=st.file_uploader("Upload your resume(PDF)...",type=["pdf"])
65
+
66
+
67
+ # if uploaded_file is not None:
68
+ # st.write("PDF Uploaded Successfully")
69
+
70
+
71
+ with st.sidebar:
72
+ st.title(' :blue[_AI Generated ATS] πŸ€–')
73
+ st.subheader('Parameters')
74
+
75
+ with st.spinner("Loading Model..."):
76
+ llm = ats.model()
77
+ submit1 = st.button("Tell Me About the Resume")
78
+
79
+ # submit2 = st.button("How Can I Improvise my Skills")
80
+
81
+ submit3 = st.button("Percentage match")
82
+
83
+ input_prompt1 = """
84
+ You are an experienced Technical Human Resource Manager,your task is to review the provided resume against the job description.
85
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
86
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
87
+
88
+ Job Description: {input_text}
89
+ Resume: {doc}
90
+ """
91
+
92
+ input_prompt3 = """
93
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality,
94
+ your task is to evaluate the resume against the provided job description. give me the percentage of match if the resume matches
95
+ the job description. First the output should come as percentage and then keywords missing and last final thoughts.
96
+
97
+ Job Description: {input_text}
98
+ Resume: {doc}
99
+ """
100
+
101
+ if submit1:
102
+ if doc is not None:
103
+ response=ats.get_gemini_response(llm=llm,template=input_prompt1,doc=doc,input_text=input_text)
104
+ st.subheader("The Repsonse is")
105
+ st.write(response)
106
+ else:
107
+ st.write("Please uplaod the resume")
108
+
109
+ elif submit3:
110
+ if doc is not None:
111
+ response=ats.get_gemini_response(llm=llm,template=input_prompt3,doc=doc,input_text=input_text)
112
+ st.subheader("The Repsonse is")
113
+ st.write(response)
114
+ else:
115
+ st.write("Please uplaod the resume")
116
+
117
+ if __name__ == "__main__":
118
+ run_ats()
blogger.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # blogger.py
2
+ import os
3
+ import pyperclip
4
+ import streamlit as st
5
+ from dotenv import load_dotenv
6
+ import speech_recognition as sr
7
+ import google.generativeai as genai
8
+ from langchain.prompts import PromptTemplate
9
+ from langchain_google_genai import ChatGoogleGenerativeAI
10
+
11
+ class Blog(object):
12
+ def __init__(self, title="AI Blogger"):
13
+ self.title = title
14
+
15
+ @staticmethod
16
+ def model():
17
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
18
+ return ChatGoogleGenerativeAI(model="gemini-pro")
19
+
20
+ @staticmethod
21
+ def getLLamaresponse(llm, input_text, tone, lang, blog_style, no_words, doc='', info=''):
22
+ template = """
23
+ Write a {tone} blog in {lang} as {blog_style} for a topic {input_text} within {no_words} words with references and video links also if possible and ends with a conclusion. {info} {doc}
24
+ """.format(tone=tone, lang=lang, blog_style=blog_style, input_text=input_text,
25
+ no_words=no_words,doc=doc, info=info)
26
+ response = llm.invoke(template)
27
+ return response.content
28
+
29
+ @staticmethod
30
+ def copy_text(answer, copy_button=False):
31
+ pyperclip.copy(answer)
32
+ if copy_button:
33
+ st.toast("Text copied to clipboard!", icon="πŸ“‹")
34
+
35
+ @staticmethod
36
+ def record_audio():
37
+ r = sr.Recognizer()
38
+ with st.spinner("Recording..."):
39
+ with sr.Microphone() as source:
40
+ r.adjust_for_ambient_noise(source)
41
+ with st.spinner("Say Something..."):
42
+ audio = r.listen(source, timeout=5)
43
+ with st.spinner("Processing..."):
44
+ try:
45
+ text = r.recognize_google(audio)
46
+ st.session_state['input_text'] = text
47
+ return text
48
+ except sr.UnknownValueError:
49
+ st.write("Sorry, I could not understand what you said. Please try again or write in text box.")
50
+ return ""
51
+ except sr.RequestError as e:
52
+ st.write(f"Could not request results; {e}")
53
+ return ""
54
+
55
+ @staticmethod
56
+ def input_state(input_text):
57
+ if isinstance(input_text, str):
58
+ st.session_state['input_text'] = input_text
59
+
60
+ def run_blogger(doc=''):
61
+ load_dotenv()
62
+ blog = Blog()
63
+
64
+ st.header(blog.title + " πŸ€–", divider='rainbow')
65
+
66
+ hide_streamlit_style = """
67
+ <style>
68
+ #MainMenu {visibility: hidden;}
69
+ footer {visibility: hidden;}
70
+ </style>
71
+ """
72
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
73
+
74
+ button_disabled = True
75
+
76
+ if button_disabled:
77
+ st.toast("Mic Button is disabled in production. HF Don't have Audio Device")
78
+
79
+ col1, col2 = st.columns([20, 3])
80
+
81
+ with col1:
82
+ text = st.empty()
83
+ input_text = text.text_input("Enter the Blog Topic")
84
+
85
+ with col2:
86
+ recorder = st.button("πŸŽ™οΈ", help="Blog Topic by Voice", key="mic", disabled=button_disabled)
87
+
88
+ if recorder:
89
+ recorded_text = blog.record_audio()
90
+ if recorded_text:
91
+ input_text = text.text_input("Enter the Blog Topic", value=recorded_text)
92
+
93
+ if doc:
94
+ input_text = text.text_area("Enter the Blog Topic", value=doc)
95
+ input_text = "Reference: "+ input_text
96
+
97
+ with st.sidebar:
98
+ st.title(' :blue[_AI Generated Blog_] πŸ€–')
99
+ st.subheader('Parameters')
100
+ no_words = st.sidebar.slider('Maximum Characters', min_value=100, max_value=5000, value=1000, step=100)
101
+ blog_style = st.selectbox('Writing the blog for', ('Researchers', 'Data Scientist', 'Common People'), index=0)
102
+ tone = st.selectbox('Desired Tone', ('Informative', 'Casual', 'Persuasive', 'Formal', 'Humorous'), index=0)
103
+ lang = st.text_input('Language', 'English')
104
+ info = st.text_area('Specific Instruction')
105
+ with st.spinner("Loading Model..."):
106
+ llm = blog.model()
107
+
108
+ submit = st.button("Generate Blog", on_click=lambda: blog.input_state(input_text))
109
+
110
+ if submit:
111
+ with st.spinner("Generating Blog..."):
112
+ answer = blog.getLLamaresponse(llm, st.session_state['input_text'], tone, lang, blog_style, no_words, doc, info)
113
+ st.success('Blog Generated!', icon="βœ…")
114
+ st.write(answer)
115
+ st.markdown(''':orange[Run in your system to access Copy to Clipboard Feature]''')
116
+
117
+ if __name__ == "__main__":
118
+ run_blogger()
gist.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pyperclip
3
+ import streamlit as st
4
+ from dotenv import load_dotenv
5
+ import speech_recognition as sr
6
+ import google.generativeai as genai
7
+ from langchain.prompts import PromptTemplate
8
+ from langchain_google_genai import ChatGoogleGenerativeAI
9
+
10
+ class Summary(object):
11
+ def __init__(self, title="AI Summarizer"):
12
+ self.title = title
13
+
14
+ @staticmethod
15
+ def model():
16
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
+ return ChatGoogleGenerativeAI(model="gemini-pro")
18
+
19
+ @staticmethod
20
+ def getLLamaresponse(llm, input_text, tone, lang, gist_style, no_words, info=''):
21
+ template = """
22
+ Write a {tone} summary in {lang} as {gist_style} within {no_words} words.
23
+ Text: {input_text}
24
+ {info}
25
+ """.format(tone=tone, lang=lang, gist_style=gist_style, input_text=input_text,
26
+ no_words=no_words, info=info)
27
+ response = llm.invoke(template)
28
+ return response.content
29
+ # return formated_prompt
30
+
31
+ @staticmethod
32
+ def copy_text(answer, copy_button=False):
33
+ pyperclip.copy(answer)
34
+ if copy_button:
35
+ st.toast("Text copied to clipboard!", icon="πŸ“‹")
36
+
37
+ @staticmethod
38
+ def record_audio():
39
+ r = sr.Recognizer()
40
+ with st.spinner("Recording..."):
41
+ with sr.Microphone() as source:
42
+ r.adjust_for_ambient_noise(source)
43
+ with st.spinner("Say Something..."):
44
+ audio = r.listen(source, timeout=5)
45
+ with st.spinner("Processing..."):
46
+ try:
47
+ text = r.recognize_google(audio)
48
+ st.session_state['input_text'] = text
49
+ return text
50
+ except sr.UnknownValueError:
51
+ st.write("Sorry, I could not understand what you said. Please try again or write in text box.")
52
+ return ""
53
+ except sr.RequestError as e:
54
+ st.write(f"Could not request results; {e}")
55
+ return ""
56
+
57
+ @staticmethod
58
+ def input_state(input_text):
59
+ if isinstance(input_text, str):
60
+ st.session_state['input_text'] = input_text
61
+
62
+
63
+
64
+ def run_gist(doc=''):
65
+ load_dotenv()
66
+ gist = Summary()
67
+
68
+ st.header(gist.title + " πŸ€–", divider='rainbow')
69
+
70
+ hide_streamlit_style = """
71
+ <style>
72
+ #MainMenu {visibility: hidden;}
73
+ footer {visibility: hidden;}
74
+ </style>
75
+ """
76
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
77
+
78
+ button_disabled = False
79
+
80
+ if button_disabled:
81
+ st.toast("Mic Button is disabled in production. HF Don't have Audio Device")
82
+
83
+ col1, col2 = st.columns([20, 3])
84
+
85
+ with col1:
86
+ text = st.empty()
87
+ input_text = text.text_area("Enter Text")
88
+
89
+ with col2:
90
+ recorder = st.button("πŸŽ™οΈ", help="Text by Voice", key="mic", disabled=button_disabled)
91
+
92
+ if recorder:
93
+ recorded_text = gist.record_audio()
94
+ if recorded_text:
95
+ input_text = text.text_area("Enter Text", value=recorded_text)
96
+
97
+ if doc:
98
+ input_text = text.text_area("Enter Text", value=doc)
99
+
100
+ with st.sidebar:
101
+ st.title(' :blue[_AI Generated Summary_] πŸ€–')
102
+ st.subheader('Parameters')
103
+ no_words = st.sidebar.slider('Maximum Characters', min_value=100, max_value=5000, value=1000, step=100)
104
+ gist_style = st.selectbox('Writing the Summary for', ('Researchers', 'Data Scientist', 'Common People'), index=0)
105
+ tone = st.selectbox('Desired Tone', ('Informative', 'Casual', 'Persuasive', 'Formal', 'Humorous'), index=0)
106
+ lang = st.text_input('Language', 'English')
107
+ info = st.text_area('Specific Instruction')
108
+ with st.spinner("Loading Model..."):
109
+ llm = gist.model()
110
+
111
+ submit = st.button("Generate Summary", on_click=lambda: gist.input_state(input_text))
112
+ print("Session: ", st.session_state)
113
+ if submit:
114
+ with st.spinner("Generating Summary..."):
115
+ answer = gist.getLLamaresponse(llm, st.session_state['input_text'], tone, lang, gist_style, no_words, info)
116
+ st.success('Summary Generated!', icon="βœ…")
117
+ st.write(answer)
118
+ st.markdown(''':orange[Run in your system to access Copy to Clipboard Feature]''')
119
+
120
+ if __name__ == "__main__":
121
+ run_gist()
requirements.txt CHANGED
@@ -2,8 +2,14 @@ google-generativeai
2
  langchain-google-genai
3
  langchain
4
  streamlit
 
5
  pyperclip
6
  huggingface_hub
7
  python-dotenv
8
  SpeechRecognition
9
- PyAudio
 
 
 
 
 
 
2
  langchain-google-genai
3
  langchain
4
  streamlit
5
+ pdf2image
6
  pyperclip
7
  huggingface_hub
8
  python-dotenv
9
  SpeechRecognition
10
+ PyAudio
11
+ pdfplumber
12
+ python-docx
13
+
14
+
15
+ https://github.com/oschwartz10612/poppler-windows/releases/download/v24.02.0-0/Release-24.02.0-0.zip