File size: 1,645 Bytes
c75c03b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from langchain.llms import OpenAI
import streamlit as st
import os
from openaiapikey import openai_key
from langchain import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains import SequentialChain



os.environ['OPENAI_API_KEY'] = openai_key

st.title('Book Summary')

input_text = st.text_input("Search the book you want")
#Prompt Template
first_input_prompt = PromptTemplate(input_variables = ['name'],
                                    template="Provide me a summary of the book {name}"
                                    )
#Open AI LLMS
llm = OpenAI(temperature=0.8)

#LLM Chain
chain1  = LLMChain(llm=llm, prompt = first_input_prompt, verbose=True, output_key = 'summaryofbook')
#Prompt Template

second_input_prompt = PromptTemplate(input_variables = ['summaryofbook'],
                                    template="when was the {summaryofbook} published"
                                    )
#LLM Chain

chain2  = LLMChain(llm=llm, prompt = second_input_prompt, verbose=True, output_key = 'bookpublishdate')


#Prompt Template

third_input_prompt = PromptTemplate(input_variables = ['summaryofbook'],
                                    template="Please tell me about the authors of the {summaryofbook}"
                                    )
#LLM Chain

chain3  = LLMChain(llm=llm, prompt = third_input_prompt, verbose=True, output_key = 'authorsofthebook')

parent_chain = SequentialChain(chains = [chain1, chain2, chain3], input_variables = ['name'], output_variables = ['summaryofbook', 'bookpublishdate','authorsofthebook'], verbose = True)

if input_text:
    st.write(parent_chain({'name':input_text}))