Spaces:
Running
Running
File size: 1,858 Bytes
50b6a69 |
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 61 |
import streamlit as st
from langchain.prompts import PromptTemplate
import os
from dotenv import load_dotenv
import google.generativeai as genai
load_dotenv()
# Configure API
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
def get_gemini_response(input_text, no_words, blog_style):
model = genai.GenerativeModel("gemini-pro")
# Prompt Template
template = """
Write a blog in {blog_style} style for the job profile. The topic is '{input_text}'.
The blog should be within {no_words} words.
"""
prompt = PromptTemplate(input_variables=["blog_style", "input_text", "no_words"],
template=template)
# Generate prompt string
prompt_text = prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words)
# Generate response
response = model.generate_content(prompt_text)
return response.text
st.set_page_config(page_title="Generate Blogs",
layout='centered',
initial_sidebar_state='collapsed')
#st.header("Generate Blogs 🤖")
# App name
st.markdown("<h4 style='text-align: center;'>Blog Generator</h4>", unsafe_allow_html=True)
input_text = st.text_input("Enter the Blog Topic")
# Creating two more columns for additional fields
col1, col2 = st.columns([5, 5])
with col1:
no_words = st.text_input('No of Words')
with col2:
blog_style = st.selectbox('Writing the blog for',
('Researchers', 'Data Scientist', 'Students'), index=0)
submit = st.button("Generate")
# Final response
if submit:
if input_text and no_words and blog_style:
response = get_gemini_response(input_text, no_words, blog_style)
st.write(response)
else:
st.warning("Please fill in all fields.")
|