url-to-post / app.py
Abhilashvj's picture
Update app.py
8f220a2
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)