Spaces:
Sleeping
Sleeping
File size: 1,901 Bytes
fe7ebd6 028c0cf fe7ebd6 028c0cf fe7ebd6 028c0cf fe7ebd6 028c0cf fe7ebd6 | 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 | import streamlit as st
# import os
from langchain.prompts import PromptTemplate
# from langchain_community.chat_models import ChatOpenAI
from langchain_google_genai import ChatGoogleGenerativeAI
from dotenv import load_dotenv
load_dotenv()
def getBlogContent(topic, number_of_words, field, points):
# llm = ChatOpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"),
# model_name=os.getenv("MODEL_NAME"), temperature=0)
gemini_llm = ChatGoogleGenerativeAI(model="gemini-pro",temperature=0.3)
template = """
You are an expert in "{field}". Write a blog to express your opinion on the following topic "{topic}".
Here are few instructions to follow for writing the blog:
* Use {number_of_words} words.
* Use simple english.
* Be succinct.
Here are few points on the topic "{topic}" to consider to get you started:
{points}
"""
prompt = PromptTemplate(
template = template,
input_variables = ['field', 'topic', 'number_of_words', 'points']
)
final_prompt = prompt.format(field=field, topic=topic, number_of_words=number_of_words, points=points)
response = gemini_llm.invoke(final_prompt)
print(response)
return response.content
st.set_page_config(page_title="Generate Blog", page_icon=":robot:",
layout='centered', initial_sidebar_state='collapsed')
st.header("Generate Blogs ")
topic_text_field = st.text_input("Enter topic to generate blog")
points_text_area = st.text_area("Enter points to consider")
col1, col2 = st.columns([5,5])
with col1:
no_words = st.number_input("Number of words", value=100)
with col2:
expert_field = st.selectbox('Expertise Field',
['Ruby On Rails', 'React', 'DevOps', 'Go Lang', 'Flutter Flow', 'NextJS'], index=0)
submit_button = st.button("Generate")
if submit_button:
st.write(getBlogContent(topic_text_field, no_words, expert_field, points_text_area))
|