import gradio as gr import requests # 🛰️ Your active live Kaggle backend tunnel link KAGGLE_BACKEND_URL = "https://gauchely-nonreconcilable-miracle.ngrok-free.dev" def chat_with_buddy(message, history): payload = {"prompt": message} # 🛡️ BYPASS HEADERS: Tells Ngrok to skip the warning page and allow the connection straight through! headers = { "ngrok-skip-browser-warning": "true", "User-Agent": "FlutterBuddyCustomClient/1.0" } try: # Fire the HTTP request directly over the web to your Kaggle dual-T4 GPUs with headers response = requests.post( f"{KAGGLE_BACKEND_URL}/generate", json=payload, headers=headers, timeout=60 # Gives the model up to 60 seconds to process the handshake ) if response.status_code == 200: return response.json().get("response", "Error: Empty text data payload returned from server.") else: return f"⚠️ Kaggle server responded with error status: {response.status_code}\nDetails: {response.text}" except gr.Error as ge: raise ge except Exception as e: return f"🚨 Connection failed. Ensure your Kaggle notebook cell is still running and hasn't timed out!\nError details: {str(e)}" # 📱 Wrap the Chat Interface in Blocks to handle themes flawlessly across all Gradio builds with gr.Blocks(theme="soft") as demo: gr.ChatInterface( fn=chat_with_buddy, title="💙 Flutter & Dart Coding Buddy", description="Your personal mobile engineering assistant. Powered by Gemma 4 31B running on distributed cloud GPUs.", examples=[ "Write a clean, responsive layout grid in Flutter.", "How do I handle state persistence safely across app restarts?", "Show me a type-safe API service layout using standard Dart patterns." ] ) if __name__ == "__main__": demo.launch()