Abhilashvj commited on
Commit
640754f
1 Parent(s): 3614ab8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ import openai
4
+
5
+
6
+ def generate_instagram_content(text_content: str, temperature=0):
7
+ prompt = f"""You are a social media influencer and writing content from websites into Instagram posts, Convert the text inside the triple backticks
8
+ to an Instagram post that would appeal to a wide verity of audience \n Website Content: ```{text_content}```"""
9
+ messages = [{"role": "user", "content": prompt}]
10
+ # response = openai.ChatCompletion.create(
11
+ response = openai.ChatCompletion.create(
12
+ model="gpt-4",
13
+ messages=messages,
14
+ temperature=temperature, # this is the degree of randomness of the model's output
15
+ max_tokens=max_tokens,
16
+ )
17
+ return response.choices[0].message["content"].strip()
18
+
19
+ def extract_text_from_url(url):
20
+ response = requests.get(url)
21
+ soup = BeautifulSoup(response.content, 'html.parser')
22
+
23
+ # Remove script and style tags
24
+ for script in soup(['script', 'style']):
25
+ script.extract()
26
+
27
+ return " ".join(soup.stripped_strings)
28
+
29
+
30
+ st.title('Instagram Post Content Generator')
31
+ url = st.text_input('Enter the URL:')
32
+ if st.button('Generate Content'):
33
+ text_content = extract_text_from_url(url)
34
+ instagram_content = generate_instagram_content(text_content)
35
+ st.write(instagram_content)