the-confused-coder commited on
Commit
55798e5
·
verified ·
1 Parent(s): 85f4f1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain_google_genai import ChatGoogleGenerativeAI
4
+ import os, spaces
5
+
6
+ os.environ['GOOGLE_API_KEY'] = os.getenv('geminiapi')
7
+
8
+ # Function for LLM response
9
+ def llm_response(user_text, number_of_words, blog_audience):
10
+ # define llm
11
+ llm = ChatGoogleGenerativeAI(model="gemini-pro")
12
+ # define prompt template
13
+ ptemplate = '''
14
+ You are an Expert Blog Writer. For the topic {user_text},
15
+ write a Blog in {number_of_words} words for an audience of {blog_audience}.
16
+ '''
17
+ prompt = PromptTemplate(template=ptemplate,input_variables=['user_text','number_of_words','blog_audience'])
18
+ final_prompt = prompt.format(user_text=user_text, number_of_words=number_of_words, blog_audience=blog_audience)
19
+ # invoke llm to get result
20
+ result = llm.invoke(final_prompt)
21
+ # print result on screen
22
+ st.write(result.content)
23
+
24
+ # define page config
25
+ st.set_page_config(
26
+ page_title="Blog Generation",
27
+ page_icon="🧊",
28
+ layout="centered",
29
+ initial_sidebar_state="collapsed",
30
+ )
31
+
32
+ st.header("Blog Generation App🧊")
33
+ user_text = st.text_input("Enter title for blog")
34
+ col1,col2 = st.columns([6,6])
35
+
36
+ with col1:
37
+ number_of_words = st.text_input("Number of words in Blog")
38
+
39
+ with col2:
40
+ blog_audience = st.selectbox("Select the audience for the Blog",
41
+ ['Data Scientist', 'Researcher', 'Common People'],
42
+ index=2)
43
+
44
+ submit_btn = st.button("Submit")
45
+
46
+ if submit_btn:
47
+ llm_response(user_text, number_of_words, blog_audience) # function call for printing results