mazed commited on
Commit
50b6a69
1 Parent(s): 7d30dd6

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +60 -0
  3. requirments.txt +4 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY = "AIzaSyBBrePLC0eqi2LTVio-a7fyFKDqnoB9HdM"
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ import os
4
+ from dotenv import load_dotenv
5
+ import google.generativeai as genai
6
+
7
+ load_dotenv()
8
+
9
+ # Configure API
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+ def get_gemini_response(input_text, no_words, blog_style):
13
+ model = genai.GenerativeModel("gemini-pro")
14
+
15
+ # Prompt Template
16
+ template = """
17
+ Write a blog in {blog_style} style for the job profile. The topic is '{input_text}'.
18
+ The blog should be within {no_words} words.
19
+ """
20
+
21
+ prompt = PromptTemplate(input_variables=["blog_style", "input_text", "no_words"],
22
+ template=template)
23
+
24
+ # Generate prompt string
25
+ prompt_text = prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words)
26
+
27
+ # Generate response
28
+ response = model.generate_content(prompt_text)
29
+
30
+ return response.text
31
+
32
+ st.set_page_config(page_title="Generate Blogs",
33
+ layout='centered',
34
+ initial_sidebar_state='collapsed')
35
+
36
+ #st.header("Generate Blogs 🤖")
37
+ # App name
38
+ st.markdown("<h4 style='text-align: center;'>Blog Generator</h4>", unsafe_allow_html=True)
39
+
40
+
41
+ input_text = st.text_input("Enter the Blog Topic")
42
+
43
+ # Creating two more columns for additional fields
44
+ col1, col2 = st.columns([5, 5])
45
+
46
+ with col1:
47
+ no_words = st.text_input('No of Words')
48
+ with col2:
49
+ blog_style = st.selectbox('Writing the blog for',
50
+ ('Researchers', 'Data Scientist', 'Students'), index=0)
51
+
52
+ submit = st.button("Generate")
53
+
54
+ # Final response
55
+ if submit:
56
+ if input_text and no_words and blog_style:
57
+ response = get_gemini_response(input_text, no_words, blog_style)
58
+ st.write(response)
59
+ else:
60
+ st.warning("Please fill in all fields.")
requirments.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ langchain
3
+ python-dotenv
4
+ google-generativeai