Spaces:
Runtime error
Runtime error
Update app.py
Browse files20 unmodified lines2122232425262732 unmodified lines6061626364656667686970717273747576777879808120 unmodified linesif data.get("connected"):return True, ""else:# Provide user the URL to connect their account or top upmessage = f"Please connect or top up to access. Visit: {data.get('url', 'No URL provided')}"return False, messageexcept Exception as e:32 unmodified linesprint(f"[Paywall] Chat completion error: {e}")return f"Error retrieving completion: {e}"# Full respond function used by Gradio chatbot interfacedef respond(message, history, system_message, max_tokens, temperature, top_p, hf_token):user_id = "demo_user" # Replace or dynamically assign per user sessionconnected, paywall_msg = check_paywall(user_id)if not connected:# User not connected. Show connection URL or message.return (history, paywall_msg)# User connected - forward chat message to paywalls chat completions endpointreply_text = chat_completion(user_id, system_message, history, message, max_tokens, temperature, top_p)history = history + [{"role": "user", "content": message}, {"role": "assistant", "content": reply_text}]return history, ""# Gradio interface setupchatbot = gr.ChatInterface(respond,type="messages",20 unmodified lines21222324252632 unmodified lines59606162636465666768697071727374757677787980818283848520 unmodified linesif data.get("connected"):return True, ""else:message = f"Please connect or top up to access. Visit: {data.get('url', 'No URL provided')}"return False, messageexcept Exception as e:32 unmodified linesprint(f"[Paywall] Chat completion error: {e}")return f"Error retrieving completion: {e}"# Updated respond function fit for Gradio ChatInterfacedef respond(message, history, system_message, max_tokens, temperature, top_p, hf_token):user_id = "demo_user" # Replace with actual user session ID# Check paywall connectionconnected, paywall_msg = check_paywall(user_id)if not connected:# When user is not connected, return empty history and paywall message stringreturn [], paywall_msg# If connected, get chatbot replyreply_text = chat_completion(user_id, system_message, history, message, max_tokens, temperature, top_p)# Append new exchange to historynew_history = history + [{"role": "user", "content": message}, {"role": "assistant", "content": reply_text}]return new_history, "" # second return clears the input box# Gradio UI setup with additional inputschatbot = gr.ChatInterface(respond,type="messages",
app.py+14-10