Spaces:
Running
Running
Update pages/community.py
Browse files- pages/community.py +76 -36
pages/community.py
CHANGED
|
@@ -3,8 +3,10 @@ import requests
|
|
| 3 |
import json
|
| 4 |
import datetime
|
| 5 |
|
|
|
|
| 6 |
SUPABASE_URL = "https://fpbuhzbdtzwomjwytqul.supabase.co"
|
| 7 |
SUPABASE_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZwYnVoemJkdHp3b21qd3l0cXVsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTE5NDk3NzYsImV4cCI6MjA2NzUyNTc3Nn0.oAa2TNNPQMyOGk63AOMZ7XKcwYvy5m-xoSWyvMZd6FY"
|
|
|
|
| 8 |
|
| 9 |
headers = {
|
| 10 |
"apikey": SUPABASE_API_KEY,
|
|
@@ -12,69 +14,107 @@ headers = {
|
|
| 12 |
"Content-Type": "application/json"
|
| 13 |
}
|
| 14 |
|
|
|
|
| 15 |
def submit_feedback(name, email, rating, comments):
|
|
|
|
| 16 |
if not all([name, email, rating, comments]):
|
| 17 |
return "β All fields are required.", name, email, rating, comments
|
| 18 |
|
| 19 |
data = {
|
| 20 |
"name": name,
|
| 21 |
"email": email,
|
| 22 |
-
"rating": rating,
|
| 23 |
"comments": comments,
|
| 24 |
"submitted": datetime.datetime.now().isoformat()
|
| 25 |
}
|
| 26 |
|
| 27 |
response = requests.post(
|
| 28 |
-
f"{SUPABASE_URL}/rest/v1/
|
| 29 |
headers=headers,
|
| 30 |
data=json.dumps(data)
|
| 31 |
)
|
| 32 |
|
| 33 |
if response.status_code == 201:
|
| 34 |
-
return
|
| 35 |
-
|
| 36 |
-
"", "", 3, "" # Reset form fields
|
| 37 |
-
)
|
| 38 |
else:
|
| 39 |
-
return
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Column():
|
| 46 |
gr.Markdown("## π Join the Community")
|
| 47 |
|
| 48 |
gr.Markdown("""
|
| 49 |
Deepfakes are becoming increasingly sophisticated. We believe that fighting misinformation is a community effort.
|
| 50 |
-
|
| 51 |
### π€ How You Can Contribute
|
| 52 |
-
- **Share your feedback** on the toolβs performance
|
| 53 |
-
- **Report suspicious media** or share verified datasets
|
| 54 |
-
- **Suggest improvements** to the detection model
|
| 55 |
-
- **Educate others** on recognizing and avoiding deepfake scams
|
| 56 |
-
|
| 57 |
### π¬ Letβs Talk
|
| 58 |
-
Join our open discussions and connect with developers, researchers, and digital safety advocates.
|
| 59 |
Whether you're a student, developer, or just curious β your voice matters.
|
| 60 |
""")
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
with gr.Row():
|
| 69 |
-
rating = gr.Slider(minimum=1, maximum=5, step=1, value=3, label="Rating", interactive=True)
|
| 70 |
-
|
| 71 |
-
comments = gr.Textbox(label="Comments", lines=3, max_lines=4, placeholder="Let us know what you think...")
|
| 72 |
-
|
| 73 |
-
submit_btn = gr.Button("Submit", variant="primary")
|
| 74 |
-
response_msg = gr.Markdown("")
|
| 75 |
-
|
| 76 |
-
submit_btn.click(
|
| 77 |
-
fn=submit_feedback,
|
| 78 |
-
inputs=[name, email, rating, comments],
|
| 79 |
-
outputs=[response_msg, name, email, rating, comments]
|
| 80 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import json
|
| 4 |
import datetime
|
| 5 |
|
| 6 |
+
# --- Supabase Configuration ---
|
| 7 |
SUPABASE_URL = "https://fpbuhzbdtzwomjwytqul.supabase.co"
|
| 8 |
SUPABASE_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZwYnVoemJkdHp3b21qd3l0cXVsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTE5NDk3NzYsImV4cCI6MjA2NzUyNTc3Nn0.oAa2TNNPQMyOGk63AOMZ7XKcwYvy5m-xoSWyvMZd6FY"
|
| 9 |
+
SUPABASE_TABLE = "feedback" # It's good practice to define the table name
|
| 10 |
|
| 11 |
headers = {
|
| 12 |
"apikey": SUPABASE_API_KEY,
|
|
|
|
| 14 |
"Content-Type": "application/json"
|
| 15 |
}
|
| 16 |
|
| 17 |
+
# --- Backend Function ---
|
| 18 |
def submit_feedback(name, email, rating, comments):
|
| 19 |
+
"""Handles the submission of feedback to the Supabase database."""
|
| 20 |
if not all([name, email, rating, comments]):
|
| 21 |
return "β All fields are required.", name, email, rating, comments
|
| 22 |
|
| 23 |
data = {
|
| 24 |
"name": name,
|
| 25 |
"email": email,
|
| 26 |
+
"rating": rating, # This will be an integer (1-5) from the Radio component
|
| 27 |
"comments": comments,
|
| 28 |
"submitted": datetime.datetime.now().isoformat()
|
| 29 |
}
|
| 30 |
|
| 31 |
response = requests.post(
|
| 32 |
+
f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}",
|
| 33 |
headers=headers,
|
| 34 |
data=json.dumps(data)
|
| 35 |
)
|
| 36 |
|
| 37 |
if response.status_code == 201:
|
| 38 |
+
# On success, return a confirmation message and clear the form fields
|
| 39 |
+
return ("β
Feedback submitted successfully!", "", "", 3, "")
|
|
|
|
|
|
|
| 40 |
else:
|
| 41 |
+
# On failure, return an error and keep the user's input
|
| 42 |
+
return ("β Failed to submit feedback. Please try again.", name, email, rating, comments)
|
| 43 |
+
|
| 44 |
+
# --- UI Layout Function ---
|
| 45 |
+
def layout(is_logged_in: gr.State):
|
| 46 |
+
"""
|
| 47 |
+
Creates the UI for the Community tab.
|
| 48 |
+
Accepts the global `is_logged_in` state to control form visibility.
|
| 49 |
+
"""
|
| 50 |
with gr.Column():
|
| 51 |
gr.Markdown("## π Join the Community")
|
| 52 |
|
| 53 |
gr.Markdown("""
|
| 54 |
Deepfakes are becoming increasingly sophisticated. We believe that fighting misinformation is a community effort.
|
|
|
|
| 55 |
### π€ How You Can Contribute
|
| 56 |
+
- **Share your feedback** on the toolβs performance
|
| 57 |
+
- **Report suspicious media** or share verified datasets
|
| 58 |
+
- **Suggest improvements** to the detection model
|
| 59 |
+
- **Educate others** on recognizing and avoiding deepfake scams
|
|
|
|
| 60 |
### π¬ Letβs Talk
|
| 61 |
+
Join our open discussions and connect with developers, researchers, and digital safety advocates.
|
| 62 |
Whether you're a student, developer, or just curious β your voice matters.
|
| 63 |
""")
|
| 64 |
|
| 65 |
+
# --- Login-Dependent Components ---
|
| 66 |
|
| 67 |
+
# Message to show when the user is logged OUT
|
| 68 |
+
logged_out_message = gr.Markdown(
|
| 69 |
+
"### <center>Please log in to leave feedback.</center>",
|
| 70 |
+
visible=True # Initially visible since the user is logged out on load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
)
|
| 72 |
+
|
| 73 |
+
# The entire feedback form, visible only when logged IN
|
| 74 |
+
with gr.Group(visible=False) as feedback_form_group:
|
| 75 |
+
gr.Markdown("### π Submit Feedback")
|
| 76 |
+
with gr.Row():
|
| 77 |
+
name = gr.Textbox(label="Name")
|
| 78 |
+
email = gr.Textbox(label="Email")
|
| 79 |
+
|
| 80 |
+
# REPLACED Slider with Radio for star rating
|
| 81 |
+
# The second item in the tuple is the value that gets returned.
|
| 82 |
+
rating = gr.Radio(
|
| 83 |
+
label="Rating",
|
| 84 |
+
choices=[
|
| 85 |
+
("β", 1),
|
| 86 |
+
("ββ", 2),
|
| 87 |
+
("βββ", 3),
|
| 88 |
+
("ββββ", 4),
|
| 89 |
+
("βββββ", 5)
|
| 90 |
+
],
|
| 91 |
+
value=3, # Default value is 3
|
| 92 |
+
interactive=True
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
comments = gr.Textbox(label="Comments", lines=3, max_lines=4, placeholder="Let us know what you think...")
|
| 96 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
| 97 |
+
response_msg = gr.Markdown()
|
| 98 |
+
|
| 99 |
+
submit_btn.click(
|
| 100 |
+
fn=submit_feedback,
|
| 101 |
+
inputs=[name, email, rating, comments],
|
| 102 |
+
outputs=[response_msg, name, email, rating, comments]
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
# --- UI Control Logic ---
|
| 106 |
+
|
| 107 |
+
def toggle_feedback_visibility(logged_in_status):
|
| 108 |
+
"""Shows/hides components based on the login status."""
|
| 109 |
+
return {
|
| 110 |
+
feedback_form_group: gr.update(visible=logged_in_status),
|
| 111 |
+
logged_out_message: gr.update(visible=not logged_in_status)
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
# This listener is the key: it triggers the visibility update
|
| 115 |
+
# whenever the is_logged_in state changes anywhere in the app.
|
| 116 |
+
is_logged_in.change(
|
| 117 |
+
fn=toggle_feedback_visibility,
|
| 118 |
+
inputs=is_logged_in,
|
| 119 |
+
outputs=[feedback_form_group, logged_out_message]
|
| 120 |
+
)
|