File size: 1,348 Bytes
8f220a2
640754f
8f220a2
640754f
8f220a2
640754f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
import requests
import streamlit as st
from bs4 import BeautifulSoup



def generate_instagram_content(text_content: str, temperature=0):
    prompt = f"""You are a social media influencer and writing content from websites into Instagram posts, Convert the text inside the triple backticks
    to an Instagram post that would appeal to a wide verity of audience \n Website Content: ```{text_content}```"""
    messages = [{"role": "user", "content": prompt}]
    # response = openai.ChatCompletion.create(
    response = openai.ChatCompletion.create(
        model="gpt-4",
        messages=messages,
        temperature=temperature,  # this is the degree of randomness of the model's output
        max_tokens=max_tokens,
    )
    return response.choices[0].message["content"].strip()
    
def extract_text_from_url(url):
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    
    # Remove script and style tags
    for script in soup(['script', 'style']):
        script.extract()
    
    return " ".join(soup.stripped_strings)


st.title('Instagram Post Content Generator')
url = st.text_input('Enter the URL:')
if st.button('Generate Content'):
    text_content = extract_text_from_url(url)
    instagram_content = generate_instagram_content(text_content)
    st.write(instagram_content)