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( "###