sancharikadebnath commited on
Commit
eef51ba
Β·
1 Parent(s): f7631ab

Added Files

Browse files
Files changed (2) hide show
  1. app.py +72 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ import google.generativeai as genai
4
+ from langchain_google_genai import ChatGoogleGenerativeAI
5
+ import pyperclip
6
+ import os
7
+ from dotenv import load_dotenv
8
+ load_dotenv()
9
+
10
+ def model():
11
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
12
+ return ChatGoogleGenerativeAI(model="gemini-pro")
13
+
14
+ def getLLamaresponse(input_text,no_words,blog_style):
15
+
16
+ ## Prompt Template
17
+
18
+ template="""
19
+ Write a {tone} blog for {blog_style} job profile for a topic {input_text}
20
+ within {no_words} words and ends with a conclusion. {info}.
21
+ """
22
+
23
+ prompt=PromptTemplate(input_variables=['tone',"blog_style","input_text",'no_words', "info"],
24
+ template=template)
25
+
26
+ ## Generate the ressponse from the LLama 2 model
27
+ response=llm.invoke(prompt.format(tone=tone,blog_style=blog_style,input_text=input_text,no_words=no_words,info=info))
28
+ print(response)
29
+ return response.content
30
+
31
+ def copy_text(answer, copy_button=False):
32
+ pyperclip.copy(answer)
33
+ if copy_button:
34
+ st.toast("Text copied to clipboard!", icon="πŸ“‹")
35
+
36
+
37
+ st.set_page_config(page_title="AI-Blogger",
38
+ page_icon='πŸ€–',
39
+ layout='centered' )
40
+
41
+ st.header("AI Blogger πŸ€–", divider='rainbow')
42
+
43
+
44
+ input_text=st.text_input("Enter the Blog Topic")
45
+
46
+ with st.sidebar:
47
+ st.title(' :blue[_AI Generated Blog_] πŸ€–')
48
+
49
+ # Refactored from <https://github.com/a16z-infra/llama2-chatbot>
50
+ st.subheader('Parameters')
51
+
52
+ no_words = st.sidebar.slider('Maximum Characters', min_value=10, max_value=5000, value=1000, step=100)
53
+ blog_style=st.selectbox('Writing the blog for',
54
+ ('Researchers','Data Scientist','Common People'),index=0)
55
+ tone=st.selectbox('Desired Tone',
56
+ ('Informative','Casual','Persuasive', 'Formal', 'Humorous'),index=0)
57
+
58
+ info = st.text_input('Specific Instruction')
59
+ with st.spinner("Loading Model..."):
60
+ llm= model()
61
+
62
+
63
+ submit=st.button("Generate Blog")
64
+
65
+
66
+ ## Final response
67
+ if submit:
68
+ with st.spinner("Generating Blog..."):
69
+ answer = getLLamaresponse(input_text,no_words,blog_style)
70
+ st.success('Blog Generated!', icon="βœ…")
71
+ st.write(answer)
72
+ st.button("πŸ“‹", on_click=copy_text(answer))
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ google-generativeai
2
+ langchain-google-genai
3
+ langchain
4
+ streamlit
5
+ pyperclip
6
+ huggingface_hub
7
+ python-dotenv