ibrahim313
commited on
Commit
β’
50aa4eb
1
Parent(s):
6ae9cf7
Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,16 @@ from streamlit.components.v1 import html
|
|
3 |
from groq import Groq
|
4 |
import os
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
# Initialize Groq
|
10 |
-
|
11 |
|
12 |
# Set the title of the app
|
13 |
-
st.title("
|
14 |
|
15 |
# Custom CSS for a professional look
|
16 |
css = """
|
@@ -40,37 +42,83 @@ html(css)
|
|
40 |
st.markdown(
|
41 |
"""
|
42 |
<div class='custom-box'>
|
43 |
-
<h2>
|
44 |
-
<p>
|
45 |
</div>
|
46 |
""", unsafe_allow_html=True
|
47 |
)
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Input for user queries
|
50 |
-
user_input = st.text_input("
|
51 |
|
52 |
-
# Function to handle Groq API call
|
53 |
-
def get_groq_response(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
try:
|
55 |
-
|
56 |
-
|
|
|
57 |
model="llama-3.1-70b-versatile",
|
58 |
)
|
59 |
return chat_completion.choices[0].message.content
|
60 |
except Exception as e:
|
61 |
return f"An error occurred: {str(e)}"
|
62 |
|
63 |
-
# Submit button
|
64 |
response = None
|
65 |
-
if st.button("
|
66 |
if user_input:
|
67 |
-
with st.spinner("
|
68 |
-
response = get_groq_response(user_input)
|
69 |
st.success(response)
|
70 |
else:
|
71 |
-
st.error("Please enter a
|
72 |
|
73 |
-
#
|
74 |
if response:
|
75 |
st.code(response)
|
76 |
st.button("Copy to clipboard", on_click=st.experimental_rerun)
|
|
|
3 |
from groq import Groq
|
4 |
import os
|
5 |
|
6 |
+
# Load Groq API key from environment variable
|
7 |
+
groq_api_key = os.getenv('api_key')
|
8 |
+
if not groq_api_key:
|
9 |
+
raise ValueError("GROQ_API_KEY environment variable is not set.")
|
10 |
|
11 |
+
# Initialize Groq client with API key
|
12 |
+
groq_client = Groq(api_key=groq_api_key)
|
13 |
|
14 |
# Set the title of the app
|
15 |
+
st.title("Social Media Post Maker for Data Science")
|
16 |
|
17 |
# Custom CSS for a professional look
|
18 |
css = """
|
|
|
42 |
st.markdown(
|
43 |
"""
|
44 |
<div class='custom-box'>
|
45 |
+
<h2>Generate Data Science Posts</h2>
|
46 |
+
<p>Create engaging social media content with AI! ππ»</p>
|
47 |
</div>
|
48 |
""", unsafe_allow_html=True
|
49 |
)
|
50 |
|
51 |
+
# Select the type of post to generate
|
52 |
+
post_type = st.selectbox(
|
53 |
+
"What type of post would you like to create?",
|
54 |
+
(
|
55 |
+
"Template-Based Post Generator",
|
56 |
+
"Data Science Meme/Quote Bot",
|
57 |
+
"Trend Explainer Bot",
|
58 |
+
"Data Science Tip Bot",
|
59 |
+
"Hashtag Suggestion Bot",
|
60 |
+
"Poll/Question Maker",
|
61 |
+
"Project Showcase Post Generator",
|
62 |
+
"Data Visual Explanation Bot"
|
63 |
+
)
|
64 |
+
)
|
65 |
+
|
66 |
# Input for user queries
|
67 |
+
user_input = st.text_input("Describe your data science topic or idea:")
|
68 |
|
69 |
+
# Function to handle Groq API call for different tasks
|
70 |
+
def get_groq_response(post_type, user_input):
|
71 |
+
if not user_input:
|
72 |
+
return "Please enter a valid query."
|
73 |
+
|
74 |
+
query_content = ""
|
75 |
+
|
76 |
+
# Match the post type with specific tasks
|
77 |
+
if post_type == "Template-Based Post Generator":
|
78 |
+
query_content = f"Generate a social media post about {user_input}."
|
79 |
+
|
80 |
+
elif post_type == "Data Science Meme/Quote Bot":
|
81 |
+
query_content = f"Generate a data science meme or quote about {user_input}."
|
82 |
+
|
83 |
+
elif post_type == "Trend Explainer Bot":
|
84 |
+
query_content = f"Explain the trend '{user_input}' in data science in a concise way."
|
85 |
+
|
86 |
+
elif post_type == "Data Science Tip Bot":
|
87 |
+
query_content = f"Give a useful data science tip about {user_input}."
|
88 |
+
|
89 |
+
elif post_type == "Hashtag Suggestion Bot":
|
90 |
+
query_content = f"Suggest relevant hashtags for {user_input}."
|
91 |
+
|
92 |
+
elif post_type == "Poll/Question Maker":
|
93 |
+
query_content = f"Generate a poll or question about {user_input} for social media."
|
94 |
+
|
95 |
+
elif post_type == "Project Showcase Post Generator":
|
96 |
+
query_content = f"Create a social media post to showcase my data science project on {user_input}."
|
97 |
+
|
98 |
+
elif post_type == "Data Visual Explanation Bot":
|
99 |
+
query_content = f"Generate a caption or explanation for a data visualization about {user_input}."
|
100 |
+
|
101 |
try:
|
102 |
+
# Make API call to Groq LLaMA model
|
103 |
+
chat_completion = groq_client.chat.completions.create(
|
104 |
+
messages=[{"role": "user", "content": query_content}],
|
105 |
model="llama-3.1-70b-versatile",
|
106 |
)
|
107 |
return chat_completion.choices[0].message.content
|
108 |
except Exception as e:
|
109 |
return f"An error occurred: {str(e)}"
|
110 |
|
111 |
+
# Submit button to generate the post
|
112 |
response = None
|
113 |
+
if st.button("Generate Post"):
|
114 |
if user_input:
|
115 |
+
with st.spinner("Generating post..."):
|
116 |
+
response = get_groq_response(post_type, user_input)
|
117 |
st.success(response)
|
118 |
else:
|
119 |
+
st.error("Please enter a topic or idea!")
|
120 |
|
121 |
+
# Allow users to copy the generated post
|
122 |
if response:
|
123 |
st.code(response)
|
124 |
st.button("Copy to clipboard", on_click=st.experimental_rerun)
|