Siddartha10 commited on
Commit
84e3fa4
β€’
1 Parent(s): 617df11

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+ import streamlit as st
4
+ import os
5
+ import google.generativeai as genai
6
+ from langchain_google_genai import ChatGoogleGenerativeAI
7
+ from langchain.prompts import PromptTemplate
8
+
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+ model = ChatGoogleGenerativeAI(model="gemini-pro")
11
+
12
+ def gemini_model(input_text,no_of_words,blog_style):
13
+ # here we are creating a template for the prompt
14
+ template = """
15
+ Write a blog on the topic of {input_text} for {blog_style} audience.
16
+ The blog should be {no_of_words} words long.
17
+ """
18
+
19
+ # here we are creating a prompt using the template and the input variables
20
+ prompt = PromptTemplate(input_variables=["input_text","blog_style","no_of_words"],template=template)
21
+
22
+ # here we are generating the blog
23
+ response = model.invoke(prompt.format(input_text=input_text,blog_style=blog_style,no_of_words=no_of_words))
24
+ print(response)
25
+ return response.content
26
+
27
+
28
+ st.set_page_config(page_title="Blog Generator", initial_sidebar_state="collapsed", layout="centered")
29
+
30
+ # Header
31
+ st.title("πŸ“ Generate Blog")
32
+
33
+ # Input Section
34
+ input_text = st.text_input("πŸ” Enter the topic of the blog you want to generate")
35
+
36
+ # Creating 2 columns for additional 2 fields
37
+ col1, col2 = st.columns([2, 2])
38
+
39
+ # Number of words input
40
+ with col1:
41
+ no_of_words = st.text_input("πŸ“ Number of Words", value="500")
42
+
43
+ # Blog style selection
44
+ with col2:
45
+ blog_style = st.selectbox("πŸ“ Writing the blog for", ("Researchers or Professionals", "General Audience"), index=0)
46
+
47
+ # Generate Button
48
+ submit_button = st.button("Generate Blog πŸš€")
49
+
50
+ # Display the generated blog on button click
51
+ if submit_button:
52
+ st.success("πŸ“– **Generated Blog:**")
53
+ generated_blog = gemini_model(input_text, no_of_words, blog_style)
54
+ st.write(generated_blog)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ google-generativeai
2
+ streamlit
3
+ python-dotenv
4
+ langchain