Spaces:
Sleeping
Sleeping
File size: 1,823 Bytes
84e3fa4 |
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 |
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")
# Header
st.title("π Generate Blog")
# Input Section
input_text = st.text_input("π Enter the topic of the blog you want to generate")
# Creating 2 columns for additional 2 fields
col1, col2 = st.columns([2, 2])
# Number of words input
with col1:
no_of_words = st.text_input("π Number of Words", value="500")
# Blog style selection
with col2:
blog_style = st.selectbox("π Writing the blog for", ("Researchers or Professionals", "General Audience"), 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)
|