meraj12 commited on
Commit
4d79c33
·
verified ·
1 Parent(s): d6865fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -24
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import streamlit as st
2
  import random
3
- import openai
4
 
5
  # Set your Groq API key
6
  GROQ_API_KEY = "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"
 
7
 
8
  # Predefined comments by category
9
  comments = {
@@ -32,45 +33,55 @@ comments = {
32
  # Function to generate AI comments
33
  def generate_ai_comment(user_input, tone):
34
  prompt = f"Generate a {tone} comment for this post: {user_input}"
35
- response = openai.ChatCompletion.create(
36
- model="gpt-3.5-turbo",
37
- messages=[{"role": "user", "content": prompt}],
38
- api_key=GROQ_API_KEY,
39
- )
40
- return response["choices"][0]["message"]["content"].strip()
41
-
42
- # Function to generate fake profile details
43
- def generate_fake_profile():
44
- names = ["John Doe", "Emily Smith", "Mike Johnson", "Sarah Brown", "Chris Lee"]
45
- avatars = [
46
- "https://randomuser.me/api/portraits/men/1.jpg",
47
- "https://randomuser.me/api/portraits/women/2.jpg",
48
- "https://randomuser.me/api/portraits/men/3.jpg",
49
- "https://randomuser.me/api/portraits/women/4.jpg",
50
- ]
51
- return random.choice(names), random.choice(avatars)
52
 
53
  # Streamlit UI
54
  st.title("Fake Facebook Comments Generator")
55
 
56
- user_input = st.text_area("Enter your post:")
 
 
 
 
 
57
  tone = st.selectbox("Choose comment tone:", ["funny", "sarcastic", "supportive", "random", "AI-Generated"])
58
 
59
  if st.button("Generate Comments"):
60
- st.subheader("Fake Comments:")
 
 
 
 
 
 
 
 
 
 
 
 
61
  for _ in range(5): # Generate 5 comments
62
- name, avatar = generate_fake_profile()
 
 
 
 
 
 
63
 
64
  if tone == "AI-Generated":
65
- comment = generate_ai_comment(user_input, "random")
66
  else:
67
  comment = random.choice(comments[tone])
68
 
69
  col1, col2 = st.columns([1, 5])
70
  with col1:
71
- st.image(avatar, width=50)
72
  with col2:
73
- st.write(f"**{name}**: {comment}")
74
 
75
  # Emoji Reactions
76
  st.subheader("React to this Post:")
 
1
  import streamlit as st
2
  import random
3
+ import requests
4
 
5
  # Set your Groq API key
6
  GROQ_API_KEY = "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"
7
+ GROQ_API_URL = "https://api.groq.com/v1/chat/completions"
8
 
9
  # Predefined comments by category
10
  comments = {
 
33
  # Function to generate AI comments
34
  def generate_ai_comment(user_input, tone):
35
  prompt = f"Generate a {tone} comment for this post: {user_input}"
36
+ headers = {"Authorization": f"Bearer {GROQ_API_KEY}", "Content-Type": "application/json"}
37
+ payload = {"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": prompt}]}
38
+ response = requests.post(GROQ_API_URL, json=payload, headers=headers).json()
39
+ return response.get("choices", [{}])[0].get("message", {}).get("content", "No response")
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  # Streamlit UI
42
  st.title("Fake Facebook Comments Generator")
43
 
44
+ # User inputs a post
45
+ st.subheader("Create a Fake Facebook Post")
46
+ user_name = st.text_input("Your Name:")
47
+ profile_pic = st.file_uploader("Upload Profile Picture", type=["jpg", "png"])
48
+ user_post = st.text_area("Enter your post:")
49
+
50
  tone = st.selectbox("Choose comment tone:", ["funny", "sarcastic", "supportive", "random", "AI-Generated"])
51
 
52
  if st.button("Generate Comments"):
53
+ st.subheader("Fake Facebook Post")
54
+ col1, col2 = st.columns([1, 5])
55
+ with col1:
56
+ if profile_pic:
57
+ st.image(profile_pic, width=50)
58
+ else:
59
+ st.image("https://randomuser.me/api/portraits/men/1.jpg", width=50) # Default pic
60
+ with col2:
61
+ st.write(f"**{user_name if user_name else 'Anonymous User'}**")
62
+ st.write(user_post)
63
+ st.write("---")
64
+
65
+ st.subheader("Comments")
66
  for _ in range(5): # Generate 5 comments
67
+ commenter_name = random.choice(["John Doe", "Emily Smith", "Mike Johnson", "Sarah Brown", "Chris Lee"])
68
+ commenter_pic = random.choice([
69
+ "https://randomuser.me/api/portraits/men/3.jpg",
70
+ "https://randomuser.me/api/portraits/women/4.jpg",
71
+ "https://randomuser.me/api/portraits/men/5.jpg",
72
+ "https://randomuser.me/api/portraits/women/6.jpg",
73
+ ])
74
 
75
  if tone == "AI-Generated":
76
+ comment = generate_ai_comment(user_post, "random")
77
  else:
78
  comment = random.choice(comments[tone])
79
 
80
  col1, col2 = st.columns([1, 5])
81
  with col1:
82
+ st.image(commenter_pic, width=50)
83
  with col2:
84
+ st.write(f"**{commenter_name}**: {comment}")
85
 
86
  # Emoji Reactions
87
  st.subheader("React to this Post:")