import gradio as gr import requests # To call your backend API # IMPORTANT: Ensure this is your correct Cloudflare Worker URL BACKEND_API_URL = "https://sm-plus-api.smplushypermedia.workers.dev" def signup_influencer(name, email, social_handle, agree_terms): if not agree_terms: return "Please accept the terms and conditions." try: response = requests.post(f"{BACKEND_API_URL}/signup", json={ "name": name, "email": email, "social_handle": social_handle, "agreed_terms": agree_terms }) response.raise_for_status() # Raise an exception for HTTP errors return "Signup successful! Please check your email for next steps." except requests.exceptions.RequestException as e: return f"Signup failed: {e}. Please try again." # --- REVISED AI GENERATOR FUNCTION --- def generate_media_content(media_topic_input): try: # Send the new input field 'media_topic' response = requests.post(f"{BACKEND_API_URL}/generate_content", json={ "media_topic": media_topic_input }) response.raise_for_status() # Raise an exception for HTTP errors # Backend now returns 'generated_text' and 'content_url' backend_response = response.json() generated_text = backend_response.get("generated_text") content_url = backend_response.get("content_url") # URL to the text file in R2 output_message = "" if generated_text: output_message += f"### Generated Content Ideas:\n{generated_text}\n\n" else: output_message += "No content ideas generated by AI.\n\n" if content_url: output_message += f"**Raw Output Link:** [View full text output]({content_url})" return gr.Markdown(output_message) # Use Markdown to display formatted text except requests.exceptions.RequestException as e: return gr.Markdown(f"Content generation failed: {e}. Please try again.") with gr.Blocks() as demo: gr.Markdown("# SM Plus Influencer Portal") with gr.Tab("Sign Up"): gr.Markdown("## Become an SM Plus Influencer") name_input = gr.Textbox(label="Your Name") email_input = gr.Textbox(label="Your Email") social_input = gr.Textbox(label="Main Social Media Handle") gr.Markdown("### Media Carriage and AI Avatar Usage Agreement") gr.Markdown("Please read the [full agreement here](link_to_your_agreement_pdf_or_page).") agree_checkbox = gr.Checkbox(label="I agree to the Media Carriage and AI Avatar Usage Agreement.") signup_button = gr.Button("Sign Up") signup_output = gr.Markdown() signup_button.click( signup_influencer, inputs=[name_input, email_input, social_input, agree_checkbox], outputs=signup_output ) with gr.Tab("Media Content Brainstormer"): # Renamed the tab gr.Markdown("## Generate Short-Form Media Content Ideas") gr.Markdown("Enter a topic or idea, and get brainstormed content concepts, visuals, and hooks. Important: Enjoy our complex reasoning model. It can inherently be slower than simpler models (like standard chat models).") # --- REVISED INPUT FIELD --- media_topic_input = gr.Textbox( label="Enter your media content topic or idea", placeholder="e.g., 'unique travel experiences', 'DIY home hacks', 'tech gadget reviews'" ) generate_button = gr.Button("Brainstorm Ideas") # Renamed the button # --- REVISED OUTPUT COMPONENT --- generated_content_output = gr.Markdown(label="Generated Content Ideas") generate_button.click( generate_media_content, # Call the revised function inputs=[media_topic_input], # Pass the new input outputs=generated_content_output ) demo.launch()