File size: 1,421 Bytes
e22dfba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st
import openai
import os

openai.api_key = os.environ.get("OPEN_AI_API")
st.title("SEO Article Writer with ChatGPT")

def generate_article(keyword, writing_style, word_count):
    #return "This is a test article generated without making API calls."
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
                {"role": "user", "content": "Write a SEO optimized word article about " + keyword},
                {"role": "user", "content": "The article should be " + writing_style},
                {"role": "user", "content": "The article length should " + str(word_count)},
            ]
    )
    result = ''
    for choice in response.choices:
        result += choice.message.content

    print(result)
    return result

keyword = st.text_input("Enter a keyword:")
writing_style = st.selectbox("Select writing style:", ["Casual", "Informative", "Professional"])
word_count = st.slider("Select word count:", min_value=1000, max_value=10000, step=100, value=3000)
submit_button = st.button("Generate Article")

if submit_button:
    message = st.empty()
    message.text("Busy generating...")
    article = generate_article(keyword, writing_style, word_count)
    message.text("")
    st.write(article)
    st.download_button(
        label="Download article",
        data=article,
        file_name= 'Article.txt',
        mime='text/txt',
    )