maaz21 commited on
Commit
ea2d73a
·
verified ·
1 Parent(s): 50c8384

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ import requests
4
+ from bs4 import BeautifulSoup
5
+ import openai # Using Groq-compatible OpenAI SDK
6
+
7
+ # Set your Groq API key and endpoint
8
+ openai.api_key = "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" # Replace with your actual Groq API key
9
+ openai.api_base = "https://api.groq.com/openai/v1"
10
+
11
+ def extract_text_from_url(url):
12
+ try:
13
+ response = requests.get(url)
14
+ soup = BeautifulSoup(response.text, 'html.parser')
15
+ paragraphs = soup.find_all('p')
16
+ text = ' '.join([p.get_text() for p in paragraphs])
17
+ return text
18
+ except Exception as e:
19
+ return f"Error fetching {url}: {e}"
20
+
21
+ def generate_blog(content, keywords):
22
+ prompt = f"""
23
+ You are a professional SEO blog writer.
24
+ Based on the following combined content, generate a completely new, attractive, and SEO-optimized blog.
25
+ Please naturally incorporate the following keywords: {', '.join(keywords)}.
26
+
27
+ Content:
28
+ {content}
29
+
30
+ Write the new blog post:
31
+ """
32
+ response = openai.ChatCompletion.create(
33
+ model="llama3-70b-8192", # LLaMA 3 via Groq
34
+ messages=[
35
+ {"role": "system", "content": "You are an expert SEO content writer."},
36
+ {"role": "user", "content": prompt}
37
+ ],
38
+ temperature=0.7,
39
+ max_tokens=1500
40
+ )
41
+ return response['choices'][0]['message']['content']
42
+
43
+ def main():
44
+ st.title("📝 Pro SEO Blog Writer")
45
+
46
+ st.subheader("Enter three blog URLs:")
47
+ url1 = st.text_input("Blog URL 1")
48
+ url2 = st.text_input("Blog URL 2")
49
+ url3 = st.text_input("Blog URL 3")
50
+
51
+ st.subheader("Enter Target Keywords (comma separated):")
52
+ keywords_input = st.text_input("Example: AI, machine learning, future technology")
53
+
54
+ if st.button("Generate New Blog"):
55
+ if url1 and url2 and url3 and keywords_input:
56
+ with st.spinner("Extracting content and generating blog..."):
57
+ content1 = extract_text_from_url(url1)
58
+ content2 = extract_text_from_url(url2)
59
+ content3 = extract_text_from_url(url3)
60
+
61
+ combined_content = content1 + "\n\n" + content2 + "\n\n" + content3
62
+ keywords = [kw.strip() for kw in keywords_input.split(",")]
63
+
64
+ new_blog = generate_blog(combined_content, keywords)
65
+
66
+ st.success("✅ Blog generated successfully!")
67
+ st.subheader("Generated Blog:")
68
+ st.write(new_blog)
69
+
70
+ st.download_button("Download Blog as TXT", data=new_blog, file_name="seo_blog.txt")
71
+ else:
72
+ st.warning("Please fill in all fields.")
73
+
74
+ if __name__ == "__main__":
75
+ main()