IamVicky111 commited on
Commit
e22dfba
·
verified ·
1 Parent(s): 0e4a2f3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import os
4
+
5
+ openai.api_key = os.environ.get("OPEN_AI_API")
6
+ st.title("SEO Article Writer with ChatGPT")
7
+
8
+ def generate_article(keyword, writing_style, word_count):
9
+ #return "This is a test article generated without making API calls."
10
+ response = openai.ChatCompletion.create(
11
+ model="gpt-3.5-turbo",
12
+ messages=[
13
+ {"role": "user", "content": "Write a SEO optimized word article about " + keyword},
14
+ {"role": "user", "content": "The article should be " + writing_style},
15
+ {"role": "user", "content": "The article length should " + str(word_count)},
16
+ ]
17
+ )
18
+ result = ''
19
+ for choice in response.choices:
20
+ result += choice.message.content
21
+
22
+ print(result)
23
+ return result
24
+
25
+ keyword = st.text_input("Enter a keyword:")
26
+ writing_style = st.selectbox("Select writing style:", ["Casual", "Informative", "Professional"])
27
+ word_count = st.slider("Select word count:", min_value=1000, max_value=10000, step=100, value=3000)
28
+ submit_button = st.button("Generate Article")
29
+
30
+ if submit_button:
31
+ message = st.empty()
32
+ message.text("Busy generating...")
33
+ article = generate_article(keyword, writing_style, word_count)
34
+ message.text("")
35
+ st.write(article)
36
+ st.download_button(
37
+ label="Download article",
38
+ data=article,
39
+ file_name= 'Article.txt',
40
+ mime='text/txt',
41
+ )