ibrahim313 commited on
Commit
dcdbbad
β€’
1 Parent(s): c202349

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -101
app.py CHANGED
@@ -1,116 +1,73 @@
 
1
  import streamlit as st
2
- from streamlit.components.v1 import html
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 = """
19
- <style>
20
- body {
21
- background-color: #f0f2f6;
22
- font-family: 'Arial', sans-serif;
23
- }
24
- .stTextInput, .stButton {
25
- margin-top: 20px;
26
- }
27
- .custom-box {
28
- padding: 20px;
29
- background-color: #ffffff;
30
- border-radius: 8px;
31
- box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
32
- }
33
- .error-msg {
34
- color: red;
35
- font-weight: bold;
36
- }
37
- .copy-btn {
38
- background-color: #4CAF50;
39
- color: white;
40
- border: none;
41
- padding: 10px 20px;
42
- border-radius: 5px;
43
- cursor: pointer;
44
- }
45
- .copy-btn:hover {
46
- background-color: #45a049;
47
- }
48
- </style>
49
- """
50
 
51
- html(css)
 
 
 
 
52
 
53
- st.markdown(
54
- """
55
- <div class='custom-box'>
56
- <h2>Generate Data Science Posts</h2>
57
- <p>Create engaging social media content with AI! πŸš€πŸ’»</p>
58
- </div>
59
- """, unsafe_allow_html=True
60
- )
61
-
62
- # Select the type of post to generate
63
- post_type = st.selectbox(
64
- "What type of post would you like to create?",
65
- (
66
- "Template-Based Post Generator",
67
- "Data Science Meme/Quote Bot",
68
- "Trend Explainer Bot",
69
- "Data Science Tip Bot",
70
- "Hashtag Suggestion Bot",
71
- "Poll/Question Maker",
72
- "Project Showcase Post Generator",
73
- "Data Visual Explanation Bot"
74
- )
75
- )
76
-
77
- # Input for user queries
78
- user_input = st.text_input("Describe your data science topic or idea:")
79
-
80
- # Function to handle Groq API call for different tasks
81
- def get_groq_response(post_type, user_input):
 
 
 
 
 
 
 
 
 
82
  if not user_input:
83
  return "Please enter a valid query."
84
 
85
- query_content = ""
86
-
87
- # Match the post type with specific tasks
88
- if post_type == "Template-Based Post Generator":
89
- query_content = f"Generate a social media post about {user_input}."
90
-
91
- elif post_type == "Data Science Meme/Quote Bot":
92
- query_content = f"Generate a data science meme or quote about {user_input}."
93
-
94
- elif post_type == "Trend Explainer Bot":
95
- query_content = f"Explain the trend '{user_input}' in data science in a concise way."
96
-
97
- elif post_type == "Data Science Tip Bot":
98
- query_content = f"Give a useful data science tip about {user_input}."
99
-
100
- elif post_type == "Hashtag Suggestion Bot":
101
- query_content = f"Suggest relevant hashtags for {user_input}."
102
-
103
- elif post_type == "Poll/Question Maker":
104
- query_content = f"Generate a poll or question about {user_input} for social media."
105
-
106
- elif post_type == "Project Showcase Post Generator":
107
- query_content = f"Create a social media post to showcase my data science project on {user_input}."
108
-
109
- elif post_type == "Data Visual Explanation Bot":
110
- query_content = f"Generate a caption or explanation for a data visualization about {user_input}."
111
 
112
  try:
113
- # Make API call to Groq LLaMA model
114
  chat_completion = groq_client.chat.completions.create(
115
  messages=[{"role": "user", "content": query_content}],
116
  model="llama-3.1-70b-versatile",
@@ -119,17 +76,33 @@ def get_groq_response(post_type, user_input):
119
  except Exception as e:
120
  return f"An error occurred: {str(e)}"
121
 
122
- # Submit button to generate the post
123
- response = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  if st.button("Generate Post"):
125
  if user_input:
126
  with st.spinner("Generating post..."):
127
- response = get_groq_response(post_type, user_input)
128
  st.success("Post generated successfully!")
129
  else:
130
  st.error("Please enter a topic or idea!")
131
 
132
- # Allow users to copy the generated post
133
  if response:
134
  st.code(response)
135
 
@@ -148,6 +121,24 @@ if response:
148
  alert("Copied to clipboard!");
149
  }}
150
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  """
152
-
153
- html(copy_button_code) # Removed unsafe_allow_html
 
1
+ import os
2
  import streamlit as st
 
3
  from groq import Groq
4
+ from streamlit.components.v1 import html
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
12
  groq_client = Groq(api_key=groq_api_key)
13
 
14
+ # Few-shot examples for inspiration
15
+ few_shot_examples = """
16
+ 🎒 **Data Scaling Showdown: Normalization vs Standardization!** πŸ“Š
17
 
18
+ Ever felt like your data is on a rollercoaster? 🎑 Some values reaching for the stars, others barely off the ground? Time to level the playing field with the dynamic duo of data scaling: **Normalization** and **Standardization!** πŸ’ͺ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ 🌈 **Normalization: The Range Ranger**
21
+ πŸ”Έ What: Squeezes your data into a cozy 0-1 range.
22
+ πŸ”Έ Why: Perfect for when your features are as different as apples and skyscrapers! πŸŽπŸ™οΈ
23
+ πŸ”Έ Best for: k-NN, neural networks, and data that's living its best non-normal life.
24
+ πŸ”Έ Superpower: Taming wild data ranges without breaking a sweat!
25
 
26
+ πŸ“Š **Standardization: The Gaussian Don**
27
+ πŸ”· What: Centers your data around 0, with a standard deviation of 1.
28
+ πŸ”· Why: Ideal when your data follows the bell curve or your algorithm is a normal distribution fan.
29
+ πŸ”· Best for: Logistic regression, SVM, and PCA - the cool kids of the ML world.
30
+ πŸ”· Superpower: Handling outliers like a boss!
31
+
32
+ πŸ₯Š **The Face-Off**
33
+ **Normalization:** "Let's all fit in this box!" πŸ“¦
34
+ **Standardization:** "Let's dance around the mean!" πŸ’ƒ
35
+
36
+ Use Normalization for diverse data like a candy store 🍭, and Standardization when your data fits the normal crowd 🎭.
37
+
38
+ #DataScience #NormalizationVsStandardization #AITricks
39
+
40
+ ---
41
+ 🎯 **Binary Classification or Multiclass? Here's How to Choose!** 🎯
42
+
43
+ Choosing between **binary** and **multiclass classification** can feel like picking the perfect dessertβ€”do you want the classic **chocolate cake** or an **exotic fruit tart**?
44
+
45
+ **Binary Classification:**
46
+ πŸ”Έ Focuses on **two classes**: cat or dog, pass or fail, true or false.
47
+ πŸ”Έ **Simpler** to model, quick to train, and widely used when the task is a straightforward **this or that** decision.
48
+
49
+ **Multiclass Classification:**
50
+ πŸ”· Handles **more than two classes**: apple, orange, banana, or even dragon fruit!
51
+ πŸ”· Complex but powerful when you need **multiple predictions** from a single model, often used in tasks like image recognition.
52
+
53
+ ---
54
+
55
+ 🧠 **How to Ace Hyperparameter Tuning!**
56
+
57
+ Tuning hyperparameters can feel like adjusting the knobs on an old radioβ€”get it just right and the music plays beautifully. 🎢
58
+
59
+ #AI #DataScienceTips #MLHacks
60
+ """
61
+
62
+ # Function to get Groq response with few-shot examples
63
+ def get_groq_response_with_few_shot(post_type, user_input):
64
  if not user_input:
65
  return "Please enter a valid query."
66
 
67
+ query_content = f"Here are a few examples of fun and engaging social media posts about data science:\n{few_shot_examples}\nNow generate a {post_type} post about {user_input} in a similar style."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  try:
70
+ # Make the API call with few-shot examples included
71
  chat_completion = groq_client.chat.completions.create(
72
  messages=[{"role": "user", "content": query_content}],
73
  model="llama-3.1-70b-versatile",
 
76
  except Exception as e:
77
  return f"An error occurred: {str(e)}"
78
 
79
+ # Streamlit UI
80
+ st.title("Social Media Post Maker for Data Science")
81
+
82
+ # User input
83
+ post_type = st.selectbox("Select the type of post:", [
84
+ "Template-Based Post",
85
+ "Data Science Meme/Quote",
86
+ "Trend Explainer",
87
+ "Data Science Tip",
88
+ "Hashtag Suggestion",
89
+ "Poll/Question Maker",
90
+ "Project Showcase",
91
+ "Data Visual Explanation"
92
+ ])
93
+
94
+ user_input = st.text_input("Enter the topic or idea for the post:")
95
+
96
+ # Generate button
97
  if st.button("Generate Post"):
98
  if user_input:
99
  with st.spinner("Generating post..."):
100
+ response = get_groq_response_with_few_shot(post_type, user_input)
101
  st.success("Post generated successfully!")
102
  else:
103
  st.error("Please enter a topic or idea!")
104
 
105
+ # Display the result
106
  if response:
107
  st.code(response)
108
 
 
121
  alert("Copied to clipboard!");
122
  }}
123
  </script>
124
+ <style>
125
+ .copy-btn {{
126
+ background-color: #007bff;
127
+ color: white;
128
+ border: none;
129
+ padding: 10px 20px;
130
+ text-align: center;
131
+ text-decoration: none;
132
+ display: inline-block;
133
+ font-size: 16px;
134
+ margin: 4px 2px;
135
+ cursor: pointer;
136
+ border-radius: 4px;
137
+ }}
138
+ .copy-btn:hover {{
139
+ background-color: #0056b3;
140
+ }}
141
+ </style>
142
  """
143
+
144
+ html(copy_button_code)