Spaces:
Sleeping
Sleeping
| 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)) | |