File size: 1,969 Bytes
ae74582
 
527f1aa
ae74582
 
 
527f1aa
 
ae74582
 
527f1aa
ae74582
 
 
 
 
 
527f1aa
ae74582
 
527f1aa
ae74582
 
 
 
527f1aa
 
ac08e58
527f1aa
 
 
 
ac08e58
 
 
 
 
 
 
 
ae74582
ac08e58
 
 
 
 
6a44fbb
527f1aa
ac08e58
 
 
ae74582
 
81a2c69
ae74582
 
 
ac08e58
ae74582
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import os
import google.generativeai as genai
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.prompts import PromptTemplate

genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
model = ChatGoogleGenerativeAI(model="gemini-pro")

def gemini_model(input_text,no_of_words,blog_style):
    # here we are creating a template for the prompt
    template = """
    Write a blog on the topic of {input_text} for {blog_style} audience. 
    The blog should be {no_of_words} words long.
    """

    # here we are creating a prompt using the template and the input variables
    prompt = PromptTemplate(input_variables=["input_text","blog_style","no_of_words"],template=template)

    # here we are generating the blog
    response = model.invoke(prompt.format(input_text=input_text,blog_style=blog_style,no_of_words=no_of_words))
    print(response)
    return response.content


# st.set_page_config(page_title="Blog Generator", initial_sidebar_state="collapsed", layout="centered")




st.set_page_config(page_title="Lets Generate Blogs",
                    page_icon='♛ ',
                    layout='centered',
                    initial_sidebar_state='collapsed')

st.header("Lets Generate Blogs Together ♛ ")

input_text=st.text_input("Enter the Blog Topic")

## creating to more columns for additonal 2 fields

col1,col2=st.columns([2,2])

with col1:
    no_of_words=st.text_input('No of Words',value = 500)
with col2:
    blog_style=st.selectbox('♛ Writing the blog for',
                            ('Kids - 5 Year olds','Grad Students','Researchers','Data Scientist','Common People'),index=0)
    

# Generate Button
submit_button = st.button("♛ Generate Blog ")

# Display the generated blog on button click
if submit_button:
    st.success("**Generated Blog:**")
    generated_blog = gemini_model(input_text, no_of_words, blog_style)
    st.write(generated_blog)