File size: 1,996 Bytes
2dcdb31
 
 
015a392
2dcdb31
 
 
 
 
462e263
 
 
 
 
 
2dcdb31
462e263
 
 
 
 
 
 
2dcdb31
 
015a392
2dcdb31
 
 
462e263
 
2dcdb31
462e263
2dcdb31
462e263
015a392
 
 
 
 
 
 
 
 
 
 
2dcdb31
 
 
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
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()