Upload files
Browse files- Api_Key.py +2 -0
- LLM_Helper.py +90 -0
- PromptHelper.py +66 -0
- UI_Helper.py +59 -0
- app.py +78 -0
- logo.png +0 -0
- requirements.txt +5 -0
Api_Key.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openapi_key = "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"
|
2 |
+
google_plam = "AIzaSyBxSZwasdkOXNmCWf59ymio46wg08dKf-w"
|
LLM_Helper.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.llms import OpenAI, GooglePalm
|
2 |
+
from Api_Key import openapi_key,google_plam
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from langchain.chains import LLMChain
|
5 |
+
import PromptHelper
|
6 |
+
|
7 |
+
google_llm = GooglePalm(google_api_key=google_plam,temperature=0.1)
|
8 |
+
|
9 |
+
def Book_Name1(main_cat):
|
10 |
+
|
11 |
+
"""
|
12 |
+
Prompt P1
|
13 |
+
Return only Education Related
|
14 |
+
"""
|
15 |
+
prompt_template_name = PromptTemplate(
|
16 |
+
input_variables=['main_cat'],
|
17 |
+
template=PromptHelper.P1
|
18 |
+
)
|
19 |
+
chain = LLMChain(llm=google_llm, prompt=prompt_template_name)
|
20 |
+
response = chain.run(main_cat=main_cat)
|
21 |
+
return response
|
22 |
+
|
23 |
+
|
24 |
+
def Book_Name1_1(main_cat):
|
25 |
+
"""
|
26 |
+
Prompt P1_1
|
27 |
+
Return only Education Related for given year
|
28 |
+
"""
|
29 |
+
prompt_template_name = PromptTemplate(
|
30 |
+
input_variables=['main_cat'],
|
31 |
+
template=PromptHelper.P1_1
|
32 |
+
)
|
33 |
+
chain = LLMChain(llm=google_llm, prompt=prompt_template_name)
|
34 |
+
response = chain.run(main_cat=main_cat)
|
35 |
+
return response
|
36 |
+
|
37 |
+
def Book_Name2(main_cat,topic):
|
38 |
+
"""
|
39 |
+
Prompt P2
|
40 |
+
Return only Education Related for ant specific topic
|
41 |
+
"""
|
42 |
+
prompt_template_name = PromptTemplate(
|
43 |
+
input_variables=['main_cat', 'topic'],
|
44 |
+
template=PromptHelper.P2
|
45 |
+
)
|
46 |
+
chain = LLMChain(llm=google_llm, prompt=prompt_template_name)
|
47 |
+
response = chain.run(main_cat=main_cat,topic=topic)
|
48 |
+
return response
|
49 |
+
|
50 |
+
def Book_Name3(main_cat,topic,p_year):
|
51 |
+
"""
|
52 |
+
Prompt P3
|
53 |
+
Return only Education Related for ant specific topic for given year
|
54 |
+
"""
|
55 |
+
prompt_template_name = PromptTemplate(
|
56 |
+
input_variables=['main_cat', 'topic', 'p_year'],
|
57 |
+
template=PromptHelper.P3
|
58 |
+
)
|
59 |
+
chain = LLMChain(llm=google_llm, prompt=prompt_template_name)
|
60 |
+
response = chain.run(main_cat=main_cat,topic=topic,p_year=p_year)
|
61 |
+
return response
|
62 |
+
|
63 |
+
def Book_Name4(main_cat,genres):
|
64 |
+
"""
|
65 |
+
Prompt P4
|
66 |
+
Return only Non Education Related for any specific list of genres
|
67 |
+
"""
|
68 |
+
prompt_template_name = PromptTemplate(
|
69 |
+
input_variables=['main_cat', 'genres'],
|
70 |
+
template=PromptHelper.P4
|
71 |
+
)
|
72 |
+
chain = LLMChain(llm=google_llm, prompt=prompt_template_name)
|
73 |
+
response = chain.run(main_cat=main_cat,genres=genres)
|
74 |
+
return response
|
75 |
+
|
76 |
+
def Book_Name5(main_cat,genres,p_year):
|
77 |
+
"""
|
78 |
+
Prompt P5
|
79 |
+
Return only Non Education Related for any specific list of genres for given year
|
80 |
+
"""
|
81 |
+
prompt_template_name = PromptTemplate(
|
82 |
+
input_variables=['main_cat', 'list_sub_cat', 'p_year'],
|
83 |
+
template=PromptHelper.P5
|
84 |
+
)
|
85 |
+
chain = LLMChain(llm=google_llm, prompt=prompt_template_name)
|
86 |
+
response = chain.run(main_cat=main_cat,genres=genres,p_year=p_year)
|
87 |
+
return response
|
88 |
+
|
89 |
+
if __name__ == "__main__":
|
90 |
+
print(Book_Name5('Non Education', 'Horror', '2002'))
|
PromptHelper.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
P1 = """Use the following pieces of information to give the real book name .
|
2 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
3 |
+
|
4 |
+
Main Categoy : {main_cat}
|
5 |
+
|
6 |
+
Only return one book name along with published year and author in following formate
|
7 |
+
Book name (published year) by author name.
|
8 |
+
, nothing else., nothing else.
|
9 |
+
"""
|
10 |
+
|
11 |
+
P1_1 = """Use the following pieces of information to give the real book name .
|
12 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
13 |
+
|
14 |
+
Main Categoy : {main_cat}
|
15 |
+
Published in : {p_year}
|
16 |
+
|
17 |
+
Only return one book name along with published year and author in following formate
|
18 |
+
Book name (published year) by author name.
|
19 |
+
, nothing else., nothing else.
|
20 |
+
"""
|
21 |
+
|
22 |
+
P2 = """Use the following pieces of information to give the real book name .
|
23 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
24 |
+
|
25 |
+
Main Categoy : {main_cat}
|
26 |
+
Topic Name : {topic}
|
27 |
+
|
28 |
+
Only return one book name along with published year and author in following formate
|
29 |
+
Book name (published year) by author name.
|
30 |
+
, nothing else., nothing else.
|
31 |
+
"""
|
32 |
+
|
33 |
+
P3 = """Use the following pieces of information to give the real book name .
|
34 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
35 |
+
|
36 |
+
Main Categoy : {main_cat}
|
37 |
+
Topic Name : {topic}
|
38 |
+
Published in : {p_year}
|
39 |
+
|
40 |
+
Only return one book name along with published year and author in following formate
|
41 |
+
Book name (published year) by author name.
|
42 |
+
, nothing else., nothing else.
|
43 |
+
"""
|
44 |
+
|
45 |
+
P4 = """Use the following pieces of information to give the real book name .
|
46 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
47 |
+
|
48 |
+
Main Categoy : {main_cat}
|
49 |
+
List of Genres : {genres}
|
50 |
+
|
51 |
+
Only return one book name along with published year and author in following formate
|
52 |
+
Book name (published year) by author name.
|
53 |
+
, nothing else., nothing else.
|
54 |
+
"""
|
55 |
+
|
56 |
+
P5 = """Use the following pieces of information to give the real book name .
|
57 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
58 |
+
|
59 |
+
Main Categoy : {main_cat}
|
60 |
+
List of Genres : {genres}
|
61 |
+
Published in : {p_year}
|
62 |
+
|
63 |
+
Only return one book name along with published year and author in following formate
|
64 |
+
Book name (published year) by author name.
|
65 |
+
, nothing else.
|
66 |
+
"""
|
UI_Helper.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
|
4 |
+
def dropdown_with_checkbox():
|
5 |
+
# options = ['Horror', 'Drama', 'Comic', 'Romance'] # Options for the dropdown
|
6 |
+
options = ["Fantasy",
|
7 |
+
"Science Fiction",
|
8 |
+
"Action & Adventure",
|
9 |
+
"Mystery",
|
10 |
+
"Horror",
|
11 |
+
"Thriller & Suspense",
|
12 |
+
"Historical Fiction",
|
13 |
+
"Romance",
|
14 |
+
"Magic",
|
15 |
+
"Novel",
|
16 |
+
"Short Story",
|
17 |
+
"Children’s",
|
18 |
+
"Memoir & Autobiography",
|
19 |
+
"Biography",
|
20 |
+
"Food & Drink",
|
21 |
+
"Art & Photography",
|
22 |
+
"History",
|
23 |
+
"Travel",
|
24 |
+
"True Crime",
|
25 |
+
"Humor",
|
26 |
+
"Religion",
|
27 |
+
"Science & Technology"]
|
28 |
+
selected_options = st.multiselect('Select Geners:', options) # Dropdown with checkboxes
|
29 |
+
|
30 |
+
return selected_options
|
31 |
+
|
32 |
+
|
33 |
+
def number_input():
|
34 |
+
number = st.number_input("Enter a number between 1000 and 2023", min_value=1000, max_value=2023, step=1)
|
35 |
+
|
36 |
+
return number
|
37 |
+
|
38 |
+
|
39 |
+
def radio_button():
|
40 |
+
options = ['',
|
41 |
+
'Education',
|
42 |
+
'Non Education'] # Options for the radio button
|
43 |
+
selected_option = st.radio('Enter Year:', options) # Radio button
|
44 |
+
|
45 |
+
return selected_option
|
46 |
+
|
47 |
+
|
48 |
+
def radio_button2():
|
49 |
+
options = ['All',
|
50 |
+
'Custome Year'] # Options for the radio button
|
51 |
+
selected_option = st.radio('Select Option:', options) # Radio button
|
52 |
+
|
53 |
+
return selected_option
|
54 |
+
|
55 |
+
|
56 |
+
def text_box():
|
57 |
+
user_input = st.text_input('Enter topic name:') # Text input box
|
58 |
+
|
59 |
+
return user_input
|
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import LLM_Helper
|
2 |
+
import streamlit as st
|
3 |
+
import UI_Helper
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Page icon
|
7 |
+
icon = Image.open('logo.png')
|
8 |
+
|
9 |
+
# Page config
|
10 |
+
st.set_page_config(page_title="Book Name Genrator",
|
11 |
+
page_icon=icon,
|
12 |
+
layout="wide"
|
13 |
+
)
|
14 |
+
|
15 |
+
company_logo_path = 'logo.png'
|
16 |
+
st.image(company_logo_path, width=50)
|
17 |
+
|
18 |
+
st.title("Book Name Generator")
|
19 |
+
#st.sidebar.title("What you want")
|
20 |
+
|
21 |
+
def main():
|
22 |
+
global submitted, prompt, selected_values2, response
|
23 |
+
selected_value1 = UI_Helper.radio_button()
|
24 |
+
if selected_value1 == '':
|
25 |
+
submitted = st.button('Submit')
|
26 |
+
elif selected_value1 == 'Education':
|
27 |
+
input_text = UI_Helper.text_box()
|
28 |
+
selected_value3 = UI_Helper.radio_button2()
|
29 |
+
if input_text == '':
|
30 |
+
response = LLM_Helper.Book_Name1(selected_value1)
|
31 |
+
design = "#" * (len(response)*2)
|
32 |
+
#prompt = f"I want to read a book related to Education, Give me one name only with year with writer name."
|
33 |
+
submitted = st.button('Submit')
|
34 |
+
else:
|
35 |
+
if selected_value3 == 'All':
|
36 |
+
response = LLM_Helper.Book_Name2(selected_value1,input_text)
|
37 |
+
design = "#" * (len(response)*2)
|
38 |
+
#prompt = f"I want to read a book related to Education and the topic i want is {input_text}, Give me one name only with year with writer name."
|
39 |
+
submitted = st.button('Submit')
|
40 |
+
else:
|
41 |
+
entered_number = UI_Helper.number_input()
|
42 |
+
response = LLM_Helper.Book_Name3(selected_value1,input_text,entered_number)
|
43 |
+
design = "#" * (len(response)*2)
|
44 |
+
#prompt = f"I want to read a book of Education related to {input_text} published in {entered_number}, Give me one name only with year with writer name."
|
45 |
+
submitted = st.button('Submit')
|
46 |
+
elif selected_value1 == 'Non Education':
|
47 |
+
selected_values2 = UI_Helper.dropdown_with_checkbox()
|
48 |
+
selected_value3 = UI_Helper.radio_button2()
|
49 |
+
if selected_value3 == 'All':
|
50 |
+
response = LLM_Helper.Book_Name4(selected_value1,selected_values2)
|
51 |
+
design = "#" * (len(response)*2)
|
52 |
+
#prompt = f"I want to read a book of combined genres like {', '.join(selected_values2)}, Give me one name only with year with writer name."
|
53 |
+
submitted = st.button('Submit')
|
54 |
+
else:
|
55 |
+
entered_number = UI_Helper.number_input()
|
56 |
+
response = LLM_Helper.Book_Name5(selected_value1,selected_values2,entered_number)
|
57 |
+
design = "#" * (len(response)*2)
|
58 |
+
#prompt = f"I want to read a book of combined genres like {', '.join(selected_values2)} published in {entered_number}, Give me one name only with year with writer name."
|
59 |
+
submitted = st.button('Submit')
|
60 |
+
|
61 |
+
|
62 |
+
if submitted:
|
63 |
+
if selected_value1 == '':
|
64 |
+
st.error(f'Plese selet either Education or Non Education')
|
65 |
+
elif selected_value1 == 'Education':
|
66 |
+
st.write(design)
|
67 |
+
st.write("## " + response + " ##")
|
68 |
+
st.write(design)
|
69 |
+
elif selected_value1 == 'Non Education' and len(selected_values2) >= 1:
|
70 |
+
st.write(design)
|
71 |
+
st.write("## " + response + " ##")
|
72 |
+
st.write(design)
|
73 |
+
elif len(selected_values2) == 0:
|
74 |
+
st.error('Please enter some geners name from list.')
|
75 |
+
else:
|
76 |
+
st.error('Something went wrong please try again.')
|
77 |
+
if __name__ == "__main__":
|
78 |
+
main()
|
logo.png
ADDED
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai=1.3.9
|
2 |
+
langchain=0.0.350
|
3 |
+
streamlit=1.29.0
|
4 |
+
google-ai-generativelanguage=0.4.0
|
5 |
+
google-generativeai=0.3.1
|