theRealNG commited on
Commit
fe7ebd6
·
0 Parent(s):

blog generation initial setup

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. README.md +6 -0
  3. app.py +52 -0
  4. requirements.txt +9 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ .vscode
3
+ venv
README.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ ---
2
+ title: BlogGeneration
3
+ app_file: app.py
4
+ sdk: streamlit
5
+ sdk_version: 1.25.0
6
+ ---
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langchain.prompts import PromptTemplate
4
+ from langchain_community.chat_models import ChatOpenAI
5
+ from dotenv import load_dotenv
6
+ load_dotenv()
7
+
8
+ def getBlogContent(topic, number_of_words, field, points):
9
+ llm = ChatOpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"),
10
+ model_name="gpt-3.5-turbo-1106", temperature=0)
11
+
12
+ template = """
13
+ You are an expert in "{field}". Write a blog to express your opinion on the following topic "{topic}".
14
+ Here are few instructions to follow for writing the blog:
15
+ * Use {number_of_words} words.
16
+ * Use simple english.
17
+ * Be succinct.
18
+
19
+ Here are few points on the topic "{topic}" to consider to get you started:
20
+ {points}
21
+ """
22
+
23
+ prompt = PromptTemplate(
24
+ template = template,
25
+ input_variables = ['field', 'topic', 'number_of_words', 'points']
26
+ )
27
+
28
+ final_prompt = prompt.format(field=field, topic=topic, number_of_words=number_of_words, points=points)
29
+ response = llm.invoke(final_prompt)
30
+ print(response)
31
+ return response.content
32
+
33
+
34
+
35
+ st.set_page_config(page_title="Generate Blog", page_icon=":robot:",
36
+ layout='centered', initial_sidebar_state='collapsed')
37
+ st.header("Generate Blogs ")
38
+
39
+ topic_text_field = st.text_input("Enter topic to generate blog")
40
+ points_text_area = st.text_area("Enter points to consider")
41
+
42
+ col1, col2 = st.columns([5,5])
43
+ with col1:
44
+ no_words = st.number_input("Number of words", value=100)
45
+ with col2:
46
+ expert_field = st.selectbox('Expertise Field',
47
+ ['Ruby On Rails', 'React', 'DevOps', 'Go Lang', 'Flutter Flow', 'NextJS'], index=0)
48
+
49
+ submit_button = st.button("Generate")
50
+
51
+ if submit_button:
52
+ st.write(getBlogContent(topic_text_field, no_words, expert_field, points_text_area))
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ sentence-transformers
2
+ uvicorn
3
+ langchain
4
+ langchain-openai
5
+ langchain-community
6
+ huggingface_hub
7
+ python-box
8
+ streamlit
9
+ python-dotenv