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